gpt4 book ai didi

powershell - invoke-command 没有按预期工作

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

我正在尝试使用 invoke-command 来查找使用此代码的特定进程

Invoke-Command -ComputerName $selected_server.ServerName -ArgumentList $selected_server.ProcessId -ScriptBlock {Get-Process -Name "winlogon" | where{$_.Id -like $args[0]} }

这个命令不起作用,但是如果我使用包含在$selected_server.ProcessId 即 8900,而不是使用 $args[0],它可以工作。

我也尝试执行这个命令来验证变量是否被正确读取,看起来是这样

Invoke-Command -ComputerName $selected_server.ServerName -ArgumentList $selected_server.ProcessId -ScriptBlock {$args[0]; $args[0].gettype().fullname}

> 8900
> System.Int32

我错过了什么吗?

最佳答案

不知道为什么,但这行得通(也许 foreach-object scriptblock 中的 $args 超出范围):

Invoke-Command -ComputerName $selected_server.ServerName `
-ArgumentList $selected_server.ProcessId -ScriptBlock `
{param ($x) Get-Process -Name "winlogon" | where{$_.Id -like $x} }

关于powershell - invoke-command 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15199683/

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