Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Foreach If Service is Not Running Do . . .

$
0
0

Greetings,

When every I get a chance I got back to the basic to properly learn PowerShell.

I created a simple script to get all services and if the status is stopped change the color to red if not stopped change it to green.

Not sure why but whether the service is stopped or running its all colored green.

What am I doing wrong?

 $AllServices=Get-Service
ForEach ( $SVCin$AllServices ) {
If ( $SVC.Status-eq"Stopped" ) {
Write-Host$SVC.Name, $SVC.status-ForegroundColor Red
}
Else {
Write-Host$SVC.Name, $SVC.status-ForegroundColor Green
}
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles