我正在尝试在脚本中使用netsh更改IP地址。我收到错误:“参数不正确” 这是脚本:
$ManagmentAddress = '192.168.11.130'
Invoke-Command -ComputerName $OldName -ScriptBlock {netsh interface ip set address "Ethernet0" static $ManagmentAddress 255.255.0.0 } -Credential $Creds
如果我将命令更改为使用实际值而不是像这样的参数:
Invoke-Command -ComputerName $OldName -ScriptBlock {netsh interface ip set address "Ethernet0" static 192.168.11.130 255.255.0.0 } -Credential $Creds
有效。
答案 0 :(得分:1)
您缺少具有相应param()
值的 ScripBlock 的-ArgumentList
块。
$ManagmentAddress = '192.168.11.130'
Invoke-Command -ComputerName $OldName -ScriptBlock {param($ManagmentAddress) netsh interface ip set address "Ethernet0" static $ManagmentAddress 255.255.0.0 } -Credential $Creds -ArgumentList $ManagmentAddress