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

时间:2017-07-06 19:34:59

标签: powershell

如何获取没有使用我编写的脚本运行进程的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} 

1 个答案:

答案 0 :(得分:1)

Get-Process语句中使用If。如果返回一个进程,它将评估为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