简体   繁体   English

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

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

Powershell beginner here working in an air-gapped, Win7 environment with Powershell 4.0 so unable to import any modules or do anything sophisticated but wondering how I can achieve generating a txt file of computers on the network that are running a specific process, say wusa.exe for Windows Updates? Powershell 初学者在这里使用 Powershell 4.0 在气隙 Win7 环境中工作,因此无法导入任何模块或执行任何复杂的操作,但想知道如何在网络上生成运行特定进程的计算机的 txt 文件,比如 wusa。 Windows 更新的 exe?

I have a txt list of all the computer names already and so far have this:我已经有一个所有计算机名称的 txt 列表,到目前为止有这个:

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

But obviously that displays ALL processes, any way to cut out everything aside from a specific one but also only list the ones running said process?但显然这显示了所有进程,有什么方法可以删除除特定进程之外的所有内容,但也只列出运行所述进程的进程?

Thanks in advance.提前致谢。

The Get-Process command allows you to specify both a remote computer to run on, and what service you are looking for. 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"

Note: I used -ErrorAction SilentlyContinue as Get-Process throws an error if the process is not found.注意:我使用-ErrorAction SilentlyContinue ,因为如果找不到进程, Get-Process会抛出错误。

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

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