gpt4 book ai didi

带有 ComputerName 的 powershell Get-Process 缺少路径

转载 作者:行者123 更新时间:2023-12-03 09:56:10 24 4
gpt4 key购买 nike

我想获取某个远程机器上特定文件夹下的进程列表并杀死它们。但是,如果我添加 -ComputerName,Get-Process 不会按需要返回 Path,因此我无法使用 Path。有没有办法在特定路径下的远程机器上获取进程/停止进程?

// Paths are filled
PS C:\> Get-Process | Format-Table Name, Path
Name Path
---- ----
firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe

// Paths are empty
PS C:\> Get-Process -ComputerName localhost | Format-Table Name, Path
Name Path
---- ----
firefox

最佳答案

你可以使用 Invoke-Command如果在远程服务器上启用了远程处理,请在命令的脚本 block 中执行您的操作:

Invoke-Command -ComputerName remoteComputer -Script { param($pathFilter) Get-Process | ?{$_.Path -like $pathFilter} | Format-Table Name, Path } -Args "somefilter*"

关于带有 ComputerName 的 powershell Get-Process 缺少路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13148144/

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