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

不确定问题出在哪里。我是新手脚本编写者,所以我确定这很明显......

4

1 回答 1

0

在这一行

Get-ChildItem -include *.xml $qaprocessedpath | Where-Object {$_.LastWriteTime -lt $del_date_q } | Foreach-Object {Copy-Item -Path $_.FullName -Destination $qabackup} {Remove-Item $_.FullName}

为什么后面有两个脚本块Foreach-Object

如果您希望它们都运行,请尝试用分号分隔copy-itemand (在同一脚本块中)。remove-item正如您编写的那样,这两个脚本块被绑定到-Process参数(像往常一样)和-Begin参数。

于 2015-08-14T16:28:34.403 回答