Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. time = Get-Date -Format "yyy-MM-dd HH:mm"
  2. $logLocation = "E:\Scripts\Logs\script_SSRS_Copy.txt"
  3.  
  4. "$time : First Line" | Out-File $logLocation -Encoding utf8 -Append -Force
  5.  
  6. $userName = "generic"
  7. $password = ConvertTo-SecureString "password" -AsPlainText -Force
  8. $Creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName,$password
  9. $credPathOne = "\\10.201.176.175\Developers$"
  10.  
  11. New-PSDrive -Name Backup -PSProvider FileSystem -Root $credPathOne -Credential $Creds
  12.  
  13. ###Configuration
  14.  
  15. # This gets the files so we can provide the full path to our copy command.
  16. $files = Get-ChildItem -Path "Backup:\Developers_Stores.bak" -ErrorVariable +copyTracker
  17. $filesTwo = Get-ChildItem -Path "Backup:\Developers_Reports.bak" -ErrorVariable +copyTracker
  18.  
  19. # This will copy the files over with the name declared in the destination
  20. Copy-Item -Path $files.FullName -Destination "E:\SQLBackup\Developers_Stores.bak"  -Force -ErrorVariable +copyTracker
  21. Copy-Item -Path $filesTwo.FullName -Destination "E:\SQLBackup\Developers_Reports.bak" -Force -ErrorVariable +copyTracker
  22.  
  23. if($copyTracker.Count -gt 0){
  24.      
  25.     $errorHolder = $copyTracker | Get-Unique
  26.  
  27.     foreach($errors in $errorHolder){
  28.    
  29.         "$time : " + $errors.Exception.Message | Out-File -FilePath $logLocation -Encoding utf8 -Append -Force
  30.         }
  31. }else{
  32.  
  33.     "$time : No copy errors logged, high five!" | Out-File $logLocation -Encoding utf8 -Append -Force
  34. }
  35.  
  36. Clear-Variable time, errorHolder, copyTracker, errors, files, filesTwo -ErrorAction SilentlyContinue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement