检索未运行特定进程的PC的列表

问题描述:

如何获得没有运行使用此脚本的计算机的PC的列表?检索未运行特定进程的PC的列表

<# 
Searches AD for all computers that can ping and checks to see if a process 
is running 
#> 

Import-Module active* 

$PingTest = $null 
$Clist = @() 

Get-ADComputer -Filter * -Properties * | ? {$_.operatingsystem -like "*windows 7*"} | 
    ForEach-Object { 

     # test to see if the computer is on the network 
     $PingTest = Test-Connection -ComputerName $_.name -Count 1 -BufferSize 16 -Quiet 

     # If test is $true adds each computer to the array $Clist 
     If ($PingTest) {$Clist += $_.name} 
     Else {} 

}#ForEach 

#check for process running on each computer in the array $Clist 

Invoke-Command -ComputerName $Clist -ScriptBlock {Get-Process -Name mcshield} 
+0

只是一个侧面说明一个电子表格,如果你打算为简洁,你也可以使用的foreach对象的别名:'%'旁边位置对象的'? ' – TheIncorrigible1

使用Get-ProcessIf语句中。如果一个进程返回,它将评估为true。然后,您可以从导出列表,使用Export-Csv

$Computers = Get-ADComputer -Filter "OperatingSystem -like '*Windows 7*'" 
$ProcessRunning = $Computers | 
    ForEach-Object { 
     If (Test-Connection -ComputerName $_.name -Count 1 -BufferSize 16 -Quiet) { 
      If (Get-Process -ComputerName $_.name -Name mcshield -ErrorAction SilentlyContinue) { 
       [pscustomobject]@{ 
        'ComputerName' = $_.name 
        'Process Running' = $True 
       } 
      } Else { 
       [pscustomobject]@{ 
        'ComputerName' = $_.name 
        'Process Running' = $False 
       } 
      } 
     } 
    } 

$ProcessRunning | Export-Csv C:\example\path.csv -NoTypeInformation 
+0

谢谢,我会试试看,并告诉你它是否可以工作 –

+0

很酷我不知道pscustomobject ...非常高兴学习。 –

+0

@WrightRobert确认一个好答案的最佳方式是投票和/或选中标记作为答案。请参阅[为什么投票](https://*.com/help/why-vote)和[什么是声誉?](https://*.com/help/whats-reputation) – LotPings