移动项目在零字节上失败

时间:2012-10-30 14:39:50

标签: powershell powershell-v2.0

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

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

  

Move-Item:无法将参数绑定到参数'Path',因为它是   空值。在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
  }

1 个答案:

答案 0 :(得分:1)

改变这个:

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

并确保$scheduledpath是全局范围变量并具有值。