gpt4 book ai didi

powershell - 在脚本中时,powershell get-process行为不同

转载 作者:行者123 更新时间:2023-12-02 23:24:59 25 4
gpt4 key购买 nike

如果键入此命令,则结果是正确的:

Get-Process -ComputerName localhost -Id 1112,2436  
Get-Process -ComputerName localhost -Id 1112, 2436

注意第二个命令列表中的空格。

但是,如果我尝试在脚本中执行此操作,它将失败:
$str = '1112, 2436'  
Get-Process -ComputerName localhost -Id $str

Get-Process : Cannot bind parameter 'Id'. Cannot convert value "1112, 2436" to type "System.Int32". Error: "Input string was not in a correct format."



这也失败了:
$str = '1112,2436'  
Get-Process -ComputerName localhost -Id $str

Get-Process : Cannot find a process with the process identifier 11122436.



知道如何在Powershell脚本中将两个ID传递给命令吗?

最佳答案

1112, 2436参数中的-Id是数组声明,而不是字符串。删除引号:

$Ids = 1112, 2436 # spaces don't matter
Get-Process -ComputerName localhost -Id $Ids

关于powershell - 在脚本中时,powershell get-process行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39312051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com