Powershell:无法将数组.长度与int32进行比较

Powershell:无法将数组.长度与int32进行比较,powershell,comparison,invalidoperationexception,Powershell,Comparison,Invalidoperationexception,我正在创建一个ps脚本,它将处理不同的用户命令。 由于用户可以调用的每个函数都有不同数量的参数,因此我只想将usrInput[]数组中从索引1开始的其余部分作为usrInput[0]函数的参数传递 这就是我所做的: $function while($function -ne "backup" -or $function -ne "restore") { #Wait for user to make a valid input $usrInput = Read-Host "Enter -b

我正在创建一个ps脚本,它将处理不同的用户命令。 由于用户可以调用的每个函数都有不同数量的参数,因此我只想将usrInput[]数组中从索引1开始的其余部分作为usrInput[0]函数的参数传递

这就是我所做的:

$function
while($function -ne "backup" -or $function -ne "restore") { #Wait for user to make a valid input
    $usrInput = Read-Host "Enter -backup args[] or -restore args[] to backup or restore vms" -split " "
    $args
    for ($i = 1, $i -le $usrInput.Length, $i++) {
        $args[$i -1] = $usrInput[$i]
    }
    if ($usrInput[0] -eq "-backup") {
        backup($args)
}
    elseif ($usrInput[0] -eq "-restore") {
        restore($args)
    }
}
现在我得到的是以下内容(英语相当于德语shell输出):

为什么呢

我以为
array.Length
s类型是int

(注意:我也试着在它前面加上和,但是没有用)


非常感谢您的帮助。

问题在于您应该这样写:

for ($i = 1; $i -le $input.Length; $i++)
用“;”而不是“,”

我没有检查其余的代码,因为您的问题是关于$input.length和int32

for ($i = 1; $i -le $input.Length; $i++)