0
我正在嘗試創建一個PowerShell腳本,它將一定年齡的XML文件移動到要歸檔的網絡驅動器中。該腳本迄今:參數綁定
$qaprocessedpath = "Y:\SFTPSHARE\SFTPYMSQ\YS42C1Processed"
$qabackup = 「\\servername\S$\xmlbackup\qa"
$max_age_qa = "-1"
$curr_date = Get-Date
$del_date_q = $curr_date.AddDays($max_age_qa)
Get-ChildItem -include *.xml $qaprocessedpath | Where-Object {$_.LastWriteTime -lt $del_date_q } | Foreach-Object {Copy-Item -Path $_.FullName -Destination $qabackup} {Remove-Item $_.FullName}
此代碼將導致以下錯誤:
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At Y:\SFTPSHARE\SFTPYMSP\XMLBackup.ps1:52 char:132
+ Get-ChildItem -include *.xml $qaprocessedpath | Where-Object { $_.LastWriteTime -lt $del_date_q } | Foreach-Object {Copy-Item -Path <<<< $_.FullName -Destination $qabackup} {Remove-Item $_.FullName}
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand
不知道在哪裏的問題。我是一個新手編劇,所以我敢肯定,這東西很明顯...
邁克,謝謝你。我組合了這兩個腳本塊,並用分號分隔每行。這清除了錯誤,腳本似乎執行,但是當我檢查源目錄和目標目錄時,我發現沒有文件實際移動。這次腳本沒有錯誤,它只是沒有實際移動任何東西。 – user3361305