Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

-NoNewLine not working.

$
0
0

I'm trying to output the status of a service running on a remote server. I'm doing this for multiple servers so the format I want will read:

ServerName1: Stopped
ServerName2: Running
ServerName3: Running

My code:

$servername1 = get-service -name "someService" -computername ServerName1 | Format-Wide -Property Status | Out-String

Write-Host -nonewline "ServerName: $servername1"

My result:

ServerName1:

Stopped

ServerName2:

Running

ServerName3:

Running
-----------------------------------------------

Another variation I've tried:

$servername1 = get-service -name "someService" -computername ServerName1 | Format-Table @{n='Status';e={$_.Status}} -HideTableHeaders
if ($servername1 = "Running") {
Write-Host -nonewline "ServerName1: Running"
} elseif ($servername1 = "Stopped") {
Write-Host -nonewline "ServerName1: Stopped"
}

And the results from that actually match the format I want, but the status reads "Running" no matter what. Thanks for your help!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>