0

下面的脚本哪里出错了...它检查文件是否为零 (0) 字节,然后如果它们是,则将它们移动到文件夹中。

它在 IF 语句之外工作正常,但是当我在下面尝试它时,它无法复制文件并显示以下错误:

Move-Item:无法将参数绑定到参数“路径”,因为它为空。在 C:\Tools\jon\testing_scheduled.ps1:109 char:11 + Move-Item <<<< $moving "$scheduledpath\Move_empty" + CategoryInfo : InvalidData: (:) [Move-Item], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.MoveItemCommand

filter gettheheckout([string]$path = '.')
    {
        $move = Get-ChildItem $scheduledpath | Where-Object {$_.length -eq 0} | Foreach-Object {$_.fullName}
    }


$moving = gettheheckout
$check = @(Get-ChildItem $scheduledpath | Where-Object {$_.length -eq 0})

if ($check.length -eq 0)
{ 
    Write-host = "No files to move - Script Completed" -ForegroundColor Cyan    
} 
else 
{
    Move-Item $moving "$scheduledpath\Move_empty"

    Write-Host "Script Completed - Use Excel to Filter on commas - Have a nice day!" -ForegroundColor Cyan
  }
4

1 回答 1

1

改变这个:

filter gettheheckout([string]$path = '.')
    {
       Get-ChildItem $scheduledpath | Where-Object {$_.length -eq 0} | Foreach-Object {$_.fullName}
    }

并确保$scheduledpath是一个全局范围变量并且有一个值。

于 2012-10-30T14:44:18.490 回答