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