【问题标题】:Powershell - how to show which computers from a list are running a specific process?Powershell - 如何显示列表中的哪些计算机正在运行特定进程?
【发布时间】:2020-09-07 10:33:44
【问题描述】:

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

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

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

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

提前致谢。

【问题讨论】:

    标签: windows powershell windows-7 powershell-4.0


    【解决方案1】:

    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 会抛出错误。

    【讨论】:

    • 更有意义,知道某处需要一个 IF 语句。试一试,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 2023-04-08
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多