[英]powershell Get-Process with ComputerName is missing Path
I want to get a list of processes under specific folder on some remote machine and kill them.我想获取某个远程机器上特定文件夹下的进程列表并杀死它们。 However, if I add -ComputerName, Get-Process does not return Path as desired, thus I cannot Where with Path.
但是,如果我添加 -ComputerName,Get-Process 不会根据需要返回 Path,因此我无法使用 Path。 Is there a way to Get-Process / Stop-Process on remote machine under a specific 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
如果远程服务器上启用了 Remoting,您可以使用Invoke-Command ,并在命令的脚本块中执行您的操作:
Invoke-Command -ComputerName remoteComputer -Script { param($pathFilter) Get-Process | ?{$_.Path -like $pathFilter} | Format-Table Name, Path } -Args "somefilter*"
我有一个类似的案例,我通过使用 x64 版本的 powershell 解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.