I have a script that I will post down below, and the console feedback is kind of ugly, which I will also post below the script. I am wondering HOW and WHERE do I put a line break to ensure the console feedback I get looks nicer. I am using PowerShell ISE.
# Service Name and Server Name Variables
$SvcName = 'LoneStar - MessageRouter',
'LoneStar - TransactionHandler'
$SvrName = 'HQDEVAPP004'
#Initialize variables:
[string]$WaitForIt = ""
[string]$Verb = ""
[string]$Result = "FAILED"
$svc = (get-service -computername $SvrName -name $SvcName)
Write-host "$SvcName on $SvrName is $($svc.status)"
Switch ($svc.status) {
'Stopped' {
Write-host "Starting $SvcName..."
$Verb = "start"
$WaitForIt = 'Running'
$svc.Start()}
'Running' {
Write-host "Stopping $SvcName..."
$Verb = "stop"
$WaitForIt = 'Stopped'
$svc.Stop()}
Default {
Write-host "$SvcName is $($svc.status). Taking no action."}
}
if ($WaitForIt -ne "") {
Try {
$svc.WaitForStatus($WaitForIt,'00:00:05')
} Catch {
Write-host "After waiting for 2 minutes, $SvcName failed to $Verb."
}
$svc = (get-service -computername $SvrName -name $SvcName)
if ($svc.status -eq $WaitForIt) {$Result = 'SUCCESS'}
Write-host "$Result`: $SvcName on $SvrName is $($svc.status)"
}
This is what the console feedback looks like:
SUCCESS: LoneStar - MessageRouter LoneStar - TransactionHandler on HQQAAPP004 is Running Running
I’d like for it to look more like:
SUCCESS:
LoneStar - MessageRouter on HQQAAPP004 is Running
LoneStar - TransactionHandler on HQQAAPP004 is Running