I am attempting to copy database backups from our Prod server to our BCP server. The following script runs successfully on my desktop and on the server, in PowerShell ISE, running as the same account set in the 'Run As' field in the properties of the SQL Agent job.
When I attempt to run this through a SQL Agent job however, it fails.
Version 1
$backuppath = "\\ProdServer\Prod_Backups\msdb\FULL" $destpath = "\\BCPServer\Prod_Backups\" Get-ChildItem -path $backuppath sort-object -Property $_.CreationTime select-object -last 1 Copy-Item -Destination $destpath
Version 1 error:
The job script encountered the following errors. These errors did not stop the script: A job step received an error at line 5 in a PowerShell script. The corresponding line is 'Get-ChildItem -path $backuppath | '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot find path '\ProdServer\Prod_Backups\msdb\FULL' because it does not exist.
Version 2
$backuppath = "Microsoft.PowerShell.Core\FileSystem::\\ProdServer\Prod_Backups\msdb\FULL" $destpath = "Microsoft.PowerShell.Core\FileSystem::\\BCPServer\Prod_Backups\" Get-ChildItem -path $backuppath sort-object -Property $_.CreationTime select-object -last 1 Copy-Item -Destination $destpath
Version 2 error:
A job step received an error at line 5 in a PowerShell script. The corresponding line is 'Get-ChildItem -path $backuppath | '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Invalid Path: 'Microsoft.PowerShell.Core\FileSystem::\BCPServer\Prod_Backups\'.
-Al H