Last active
January 24, 2016 20:04
-
-
Save MattHodge/66bf00bedb98d72c2506 to your computer and use it in GitHub Desktop.
Get-ServiceHubot.ps1
This file contains hidden or 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
<# | |
.Synopsis | |
Gets service status for Hubot Script. | |
.DESCRIPTION | |
Gets service status for Hubot Script. | |
.EXAMPLE | |
Get-ServiceHubot -Name dhcp | |
#> | |
function Get-ServiceHubot | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
# Name of the Service | |
[Parameter(Mandatory=$true)] | |
$Name | |
) | |
# Create a hashtable for the results | |
$result = @{} | |
# Use try/catch block | |
try | |
{ | |
# Use ErrorAction Stop to make sure we can catch any errors | |
$service = Get-Service -Name $Name -ErrorAction Stop | |
# Create a string for sending back to slack. * and ` are used to make the output look nice in Slack. Details: http://bit.ly/MHSlackFormat | |
$result.output = "Service $($service.Name) (*$($service.DisplayName)*) is currently ``$($service.Status.ToString())``." | |
# Set a successful result | |
$result.success = $true | |
} | |
catch | |
{ | |
# If this script fails we can assume the service did not exist | |
$result.output = "Service $($Name) does not exist on this server." | |
# Set a failed result | |
$result.success = $false | |
} | |
# Return the result and conver it to json | |
return $result | ConvertTo-Json | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment