如何獲得沒有運行使用此腳本的計算機的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}
只是一個側面說明一個電子表格,如果你打算爲簡潔,你也可以使用的foreach對象的別名:'%'旁邊位置對象的'? ' – TheIncorrigible1