显示计数等于值的结果

Displaying results where count equals value

我想根据几秒钟内 CPU 的平均使用率来确定前几个进程。每个结果都需要列出 PID、Process Name 和 UserID。 该脚本需要同时在另一个域中的多个服务器上 运行。这些服务器的凭据与 运行 来自的计算机不同。

我无法让 Get-Process 工作,因为它不接受 –credentials 参数。 Invoke-Command 将无法运行,因为脚本在这些服务器上受到限制。 我在 $TopProcess 中得到的结果是:

User Name                   CPU       ID Description                                     
---------                   ---       -- -----------                                     
User73                       25    68680 App89.exe                              
User73                       25    68888 App57.exe                               
LOCAL SERVICE               2.5    63868 WmiPrvSE.exe                                    
User48                        0    66308 App38.exe                                     
User48                        0    62608 App54.exe                         
User73                       25    68888 App57.exe                               
User73                       25    68680 App89.exe                              
LOCAL SERVICE               2.5    63868 WmiPrvSE.exe                                    
User48                        0    59336 dwm.exe                                         
User48                        0    52528 App57.exe                               
User73                       25    68888 App57.exe                               
User73                       25    68680 App89.exe                              
User39                     19.5    48792 App43.exe                      
User39                      2.5    65996 App48.exe                              
LOCAL SERVICE               2.5    63868 WmiPrvSE.exe

但我只需要列出 CPU 超过 15 且被列出三次但每次只列出一次且

的结果
$Result = $TopProcess | Where {$_.CPU -gt $Threshold} | Measure | Where {$_.Count -eq $NoRS}

returns什么都没有。

使用 Group-Object cmdlet 而不是 Measure 对结果进行分组。我想你只想得到 UserName 属性:

$Result = $TopProcess | 
    Where {$_.CPU -gt $Threshold} | 
    group 'User Name' |  
    Where Count -eq $NoRS | 
    select Name