Created
December 22, 2015 08:55
-
-
Save tobyqin/d2e9ef631634123d5089 to your computer and use it in GitHub Desktop.
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
function Start-TheService([string]$svc) | |
{ | |
$STOP = "Stopped" | |
$RUN = "Running" | |
"Starting $svc..." | |
$s = get-service -name $svc | |
"Original status is : " + $s.Status | |
if($s.Status -eq $STOP) | |
{ | |
Start-service -name $s.name | |
} | |
$s = get-service -name $svc | |
"Now status is : " + $s.Status | |
"Checking ..." | |
$s = get-service -name $svc | |
if($s.Status -eq $STOP) | |
{ | |
throw "Exception: $svc cannot be started!!!" | |
} | |
"OK, all good." | |
} | |
function Stop-TheService([string]$svc) | |
{ | |
$STOP = "Stopped" | |
$RUN = "Running" | |
"Stopping $svc..." | |
$s = get-service -name $svc | |
"Original status is : " + $s.Status | |
if($s.Status -eq $RUN) | |
{ | |
stop-service -name $s.name | |
} | |
$s = get-service -name $svc | |
"Now status is : " + $s.Status | |
"Checking ..." | |
$s = get-service -name $svc | |
if($s.Status -eq $RUN) | |
{ | |
throw "Exception: $svc cannot be stopped!!!" | |
} | |
"OK, all good." | |
} | |
function Restart-TheService([string]$svc) | |
{ | |
Stop-TheService $svc | |
Start-TheService $svc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment