繁体   English   中英

Powershell - 如何显示列表中的哪些计算机正在运行特定进程?

[英]Powershell - how to show which computers from a list are running a specific process?

Powershell 初学者在这里使用 Powershell 4.0 在气隙 Win7 环境中工作,因此无法导入任何模块或执行任何复杂的操作,但想知道如何在网络上生成运行特定进程的计算机的 txt 文件,比如 wusa。 Windows 更新的 exe?

我已经有一个所有计算机名称的 txt 列表,到目前为止有这个:

$computers = gc "C:\PCList.txt"
foreach ($computer in $computers) {Get-process | out-file -Path "C:\TheseAreRunningWusa.txt"}

但显然这显示了所有进程,有什么方法可以删除除特定进程之外的所有内容,但也只列出运行所述进程的进程?

提前致谢。

Get-Process 命令允许您指定要在其上运行的远程计算机以及您正在寻找的服务。

$computers = Get-Content "C:\PCList.txt"
$output = @()

foreach ($computer in $computers) {
  if(Get-Process "myProcessName" -ComputerName $computer -ErrorAction SilentlyContinue) {
    $output += $computer
  }
}
$output | Set-Content "C:\TheseAreRunningMyProcess.txt"

注意:我使用-ErrorAction SilentlyContinue ,因为如果找不到进程, Get-Process会抛出错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM