Support Forums

Full Version: Powershell Services Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
$Services_ = Get-Service | write-output
$running = 1
$stopped = 1

write-host
write-host "#" Running Services "#" -foregroundcolor "magenta"
foreach ($objItm in $Services_) {
    $Display_ = $objItm.DisplayName
    
        If ($objItm.Status -eq "Running") {
            write-host "                         "$running")" $objItm.Name "("$Display_")" -foregroundcolor "gray"
            $running += 1
        }
}
$running -= 1
write-host

write-host "#" Stopped Services "#" -foregroundcolor "magenta"
foreach ($objItm in $Services_) {
    $Display_ = $objItm.DisplayName
    
        If ($objItm.Status -eq "Stopped") {
            write-host "                         "$stopped")" $objItm.Name "-- ("$Display_")" -foregroundcolor "gray"
            $stopped += 1
        }
}
$stopped -= 1
write-host "-------------------------------------------------------------------" -foregroundcolor "magenta"
write-host "#" There are a Total of $running Running Services, and $stopped Stoppped Services -foregroundcolor "magenta"
write-host "-------------------------------------------------------------------" -foregroundcolor "magenta"
write-host

Here's my newest powershell script, a little more advanced, using logic functions like the if statement to sort out Running and Stopped processes with an integer count for each process and details after both object items have been listed.
oooo very nice. I love powershell myself. I use it all the time at work. Very useful. I'll give this script a go
Here's an example of what it looks like in action:

*The list was too big, so I can't fit it into one screenshot, but it will list out Running services, numbered starting from 1). Then it will list Stopped services starting from 1). What you see in the script here is the last of the list in the Stopped services, and the information that it displays at the very end as a sort of "Statistic."

[Image: ibTPGnzjA.png]