Created
April 14, 2016 16:51
-
-
Save phwelo/177225d3064d774d23bdc2d22aa506b0 to your computer and use it in GitHub Desktop.
return windows service status in plaintext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_services(searchString) | |
psRepoCheck = "(Get-Service -name \"*" + searchString + "*\"|ConvertTo-Json)" | |
repoCheck = powershell_out!(psRepoCheck).stdout | |
if repoCheck && repoCheck.length >= 2 | |
svc_hash = JSON.parse(repoCheck) | |
svc_hash.each do |service| | |
if service['DisplayName'].include? searchString | |
case service['Status'] | |
when 1 | |
service[:statusString] = "Stopped" | |
when 2 | |
service[:statusString] = "Stop Pending" | |
when 3 | |
service[:statusString] = "Start Pending" | |
when 4 | |
service[:statusString] = "Running" | |
when 5 | |
service[:statusString] = "Continue Pending" | |
when 6 | |
service[:statusString] = "Pause Pending" | |
when 7 | |
service[:statusString] = "Paused" | |
else | |
service[:statusString] = "Unknown" | |
end | |
end | |
end | |
end | |
return svc_hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment