简体   繁体   中英

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?

I have a txt list of all the computer names already and so far have this:

$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.

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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