![]() |
|
[Powershell] Get System Services Sorted into Running and Stopped - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: [Powershell] Get System Services Sorted into Running and Stopped (/Thread-Powershell-Get-System-Services-Sorted-into-Running-and-Stopped) |
[Powershell] Get System Services Sorted into Running and Stopped - ArkPhaze - 11-26-2011 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-hostHere'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.
RE: [Powershell] Get System Services Sorted into Running and Stopped - 1234hotmaster - 11-26-2011 wow thats soo cool! can you also start/stop a service? RE: [Powershell] Get System Services Sorted into Running and Stopped - ArkPhaze - 11-26-2011 (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 ![]() Here are the commandlets Code: Start-ServiceCode: Stop-ServiceRE: [Powershell] Get System Services Sorted into Running and Stopped - 1234hotmaster - 11-26-2011 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... RE: [Powershell] Get System Services Sorted into Running and Stopped - ArkPhaze - 11-26-2011 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 RE: [Powershell] Get System Services Sorted into Running and Stopped - 1234hotmaster - 11-26-2011 (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. Oh thanks for the explanation ![]() but can you also do Code: foreach ($objItm in Get-Service)RE: [Powershell] Get System Services Sorted into Running and Stopped - ArkPhaze - 11-26-2011 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. |