Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell script to check if a process is running

Tags:

powershell

can somebody help me to create a powershell script to check a particular service is running in all the machines in active directory.

for example process like ccsvchst is available in all systems. I got the code for how to check in a single machine. but need to get code for all machines in AD.

$ProcessName = "ccsvchst"
if((get-process $ProcessName -ErrorAction SilentlyContinue) -eq $Null)
{ echo "Process is not running" }else{ echo "Process is running" }
like image 681
ANU Avatar asked Oct 27 '17 19:10

ANU


1 Answers

$ProcessName = "ccsvchst"
Get-ADComputer -Filter * | ForEach-Object {
    if((get-process $ProcessName -ComputerName $_.CN -ErrorAction SilentlyContinue) -eq $Null)
    { echo "Process is not running on $($_.CN)" }else{ echo "Process is running on $($_.CN)" }
}
like image 141
Sid Avatar answered Oct 02 '22 13:10

Sid