我在下面的脚本出错了...它会检查文件是否为零(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
}
答案 0 :(得分:1)
改变这个:
filter gettheheckout([string]$path = '.')
{
Get-ChildItem $scheduledpath | Where-Object {$_.length -eq 0} | Foreach-Object {$_.fullName}
}
并确保$scheduledpath
是全局范围变量并具有值。