簡體   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