Hi all-I have a PS script that I use to transfer files from our data center to our corporate location so that we can restore in our development environment on a regular basis. For some reason, the script will randomly fail during the transfer but will not return an error for some reason. Because of this I'm not able to determine the exact cause and try to rectify the situation. Here's the code I'm using. If anyone has any suggestions that would be great.Thanks[code="other"]$array = @("\\HOMESERVER\Backup")$target = "\\TARGETSERVER\SQL_Backup\"$erroractionpreference = "Stop"try{ $files = get-childitem $target -Recurse -include *.* foreach ($file in $files) { if ($file.LastWriteTime -le (get-date).addhours(-168)) { remove-item $file } } for ($i=0; $i -lt $array.length; $i++) { $source = $array[$i] $files = get-childitem $source -Recurse -include *.bak foreach ($file in $files) { if ($file.LastWriteTime -ge (get-date).addhours(-24)) { <#$targetFile = $target + $file.FullName.SubString($source.Length)#> $targetFile = $target + $file.Name <# New-Item -ItemType File -Path $targetFile -Force #> If(-not(Test-Path -Path $targetFile)) { Copy-Item $file.FullName -destination $targetFile } } } } #Everything is ok so send on to Monitor if (-not $error) { #Everything is ok. Send ok to server }}Catch{ #Everything is not ok. Send error to server}[/code]
↧