Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- time = Get-Date -Format "yyy-MM-dd HH:mm"
- $logLocation = "E:\Scripts\Logs\script_SSRS_Copy.txt"
- "$time : First Line" | Out-File $logLocation -Encoding utf8 -Append -Force
- $userName = "generic"
- $password = ConvertTo-SecureString "password" -AsPlainText -Force
- $Creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName,$password
- $credPathOne = "\\10.201.176.175\Developers$"
- New-PSDrive -Name Backup -PSProvider FileSystem -Root $credPathOne -Credential $Creds
- ###Configuration
- # This gets the files so we can provide the full path to our copy command.
- $files = Get-ChildItem -Path "Backup:\Developers_Stores.bak" -ErrorVariable +copyTracker
- $filesTwo = Get-ChildItem -Path "Backup:\Developers_Reports.bak" -ErrorVariable +copyTracker
- # This will copy the files over with the name declared in the destination
- Copy-Item -Path $files.FullName -Destination "E:\SQLBackup\Developers_Stores.bak" -Force -ErrorVariable +copyTracker
- Copy-Item -Path $filesTwo.FullName -Destination "E:\SQLBackup\Developers_Reports.bak" -Force -ErrorVariable +copyTracker
- if($copyTracker.Count -gt 0){
- $errorHolder = $copyTracker | Get-Unique
- foreach($errors in $errorHolder){
- "$time : " + $errors.Exception.Message | Out-File -FilePath $logLocation -Encoding utf8 -Append -Force
- }
- }else{
- "$time : No copy errors logged, high five!" | Out-File $logLocation -Encoding utf8 -Append -Force
- }
- Clear-Variable time, errorHolder, copyTracker, errors, files, filesTwo -ErrorAction SilentlyContinue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement