Guest User

Untitled

a guest
Oct 18th, 2017
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $error.clear()
  3. ##$erroractionpreference = "SilentlyContinue"
  4.  
  5.  
  6. $24_hrs_ago = ($(get-date).AddDays(-1))     # -format 'yyyy-MM-dd__HH-mm-ss'
  7. $pretty_today = get-date -format 'yyyyy-MM-dd__HH-mm-ss'
  8. $total_files = 0
  9. $new_files = 0
  10. $folder = 'D:\Veeam Backups\'
  11. $vrbs = 0
  12. $include_ext = '.vrb'
  13. $EXE_STR = ' '
  14.  
  15. $email_to = 'EMAIL@email.com'
  16. # $email_to = 'EMAIL@email.com'
  17. $email_from = 'EMAIL@email.com'
  18. $subject = '[ERROR] FAILED MSG GOES HERE'
  19. $body = 'Unable to find new incremental files from the past 24 hours to archive with TSM.'
  20. $smtp = 'smtp.email.com'
  21. $log_file = 'c:\scripts\logs\FILENAME.log'
  22.        
  23.  
  24.  
  25. "---------------------------------------------"        | Out-File $log_file -append
  26. "--- new file check: " + $pretty_today  +   " ---"     | Out-File $log_file -append
  27. "---------------------------------------------"        | Out-File $log_file -append
  28.  
  29.  
  30. foreach ($i in Get-ChildItem $folder)
  31. {
  32.    $total_files++
  33.      
  34.    if ($i.extension -eq $include_ext)
  35.    {
  36.         $vrbs++
  37.    
  38.    if ($i.CreationTime -gt $24_hrs_ago)
  39.    {
  40.         $new_files++
  41.        
  42.         if ($new_files -eq 1)        # just for log formatting
  43.         {
  44.             " " | Out-File $log_file -append
  45.             "  NEW FILES: " | Out-File $log_file -append
  46.         }
  47.        
  48.         #  add command to execute backup thinger here
  49.        
  50.         '   -->' + $i.FullName      | Out-File $log_file -append
  51.  
  52.         & 'C:\Program Files\Tivoli\TSM\baclient\dsmc.exe' archive -archmc=ARCHIVE7DAYS $i.FullName
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58. if ($new_files -le 0)
  59. {
  60.     send-mailmessage -to $email_to -from $email_from -subject $subject -body $body -priority High -dno onSuccess, onFailure -smtpServer $smtp
  61. }
  62. else
  63. {
  64.     " " | Out-File $log_file -append
  65. }
  66.  
  67.  
  68. "  TOTAL FILES ............................ " + $total_files | Out-File $log_file -append
  69. "  " + $include_ext + " Files ............................. " + $txts | Out-File $log_file -append
  70. "  " + $include_ext + " Files Since " + $24_hrs_ago + " ... " + $new_files | Out-File $log_file -append
  71. "------------------------------------------------" | Out-File $log_file -append
  72. "  " | Out-File $log_file -append
  73. "  " | Out-File $log_file -append
Add Comment
Please, Sign In to add comment