Login Register


[Powershell] Get System Services Sorted into Running and Stopped filter_list
Author
Message
[Powershell] Get System Services Sorted into Running and Stopped #1
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 "white" $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 "white" $stopped += 1 } } write-host "-------------------------------------------------------------------" -foregroundcolor "magenta" write-host "#" There are a Total of ($running -1) Running Services, and ($stopped -1) Stoppped Services -foregroundcolor "magenta" write-host "-------------------------------------------------------------------" -foregroundcolor "magenta" write-host

Here's another script I created which will display all of your systems currently running services and stopped services. use it as a commandlet for faster accessibility. Smile
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #2
wow thats soo cool! can you also start/stop a service?
Pierce the life fibers with your drill.

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #3
(11-26-2011, 12:33 PM)[ntdll.dll]x[advapi32.dll] Wrote: wow thats soo cool! can you also start/stop a service?

Yep, the power of powershell Smile

Here are the commandlets
Code:
Start-Service
Code:
Stop-Service
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #4
OMFG A FUNCTION FOR IT? you need to include a huge custom made file for just doing that XD
but there is a 1 line method for it too...
Pierce the life fibers with your drill.

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #5
I parse the data and pipeline it out into my own formatted sequence of data from the commandlet Get-Service in my script above, through sorting the data for each object in the array into sub array strings before moving on to the next object in the commandlet.

I could actually add them to arrays, and provide a further option as a "Menu" or something like that to take user input for stopping and starting a service too.

$Services_ basically just holds the data of the full output from Get-Service, then I tear down that pile of information and build my own smaller organized piles of that information sorting it out in the way I want it to display
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #6
(11-26-2011, 12:47 PM)Infinity Wrote: I parse the data and pipeline it out into my own formatted sequence of data from the commandlet Get-Service in my script above, through sorting the data for each object in the array into sub array strings before moving on to the next object in the commandlet.

I could actually add them to arrays, and provide a further option as a "Menu" or something like that to take user input for stopping and starting a service too.

$Services_ basically just holds the data of the full output from Get-Service, then I tear down that pile of information and build my own smaller organized piles of that information sorting it out in the way I want it to display

Oh thanks for the explanation Smile

but can you also do
Code:
foreach ($objItm in Get-Service)
directly?
Pierce the life fibers with your drill.

Reply

RE: [Powershell] Get System Services Sorted into Running and Stopped #7
Yeah, that's correct. If I want to do something else with that data though it's easier to use a variable as a placeholder for that information.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: