\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!\nUse a descriptive subject. Don't say \"Need help\" or \"PowerShell Help\", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…\n <\/blockquote>\n<\/aside>\n\n <\/p>","upvoteCount":0,"datePublished":"2021-03-31T15:32:10.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
maybe more like so?<\/p>\n
Foreach ($service in $services) {\n $Rservice = get-service -Name $service -computername CLPROD03\n If ($Rservice.status -eq 'Running') {\n Write-output $_.status\n }\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-03-31T15:35:46.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"if you just need to see it running what’s the point of If else? just select the status<\/p>\n
get-service -Name $service -computer name CLPROD03|select name,status<\/p>\n
or<\/p>\n
get-service -computername CLPROD03 |where-object {$_.DisplayName -EQ $service -and $_.status -eq 'running'}\n<\/code><\/pre>\nif necessary<\/p>\n
$services=''\nForeach ($service in $services){\n$check=get-service -computername CLPROD03 -DisplayName \"$service\"\n If ($check.status -eq 'Running')\n {\n Write-output $check.status\n }\n}\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-03-31T15:41:44.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/4","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\nmaybe more like so?<\/p>\n
Foreach ($service in $services) {\n $Rservice = get-service -Name $service -computername CLPROD03\n If ($Rservice.status -eq 'Running') {\n Write-output $_.status\n }\n}\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nShouldn’t you replace $_.status with $Rservice.status, like so?<\/p>\n
Foreach ($service in $services) {\n $Rservice = get-service -Name $service -computername CLPROD03\n If ($Rservice.status -eq 'Running') {\n Write-output $Rservice.status\n }\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-03-31T16:48:14.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/5","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"Yep Evan<\/p>","upvoteCount":0,"datePublished":"2021-03-31T16:49:24.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Thank you Neally!<\/p>","upvoteCount":0,"datePublished":"2021-03-31T16:49:28.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/7","author":{"@type":"Person","name":"sunny75","url":"https://community.spiceworks.com/u/sunny75"}},{"@type":"Answer","text":"
Thank You Jiten!<\/p>","upvoteCount":0,"datePublished":"2021-03-31T16:50:45.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/8","author":{"@type":"Person","name":"sunny75","url":"https://community.spiceworks.com/u/sunny75"}},{"@type":"Answer","text":"
Hey Jiten<\/p>\n
Just one more thing. I’m knew to Powershell and I tried looking on google how to frormat write-output,<\/p>\n
I tried using -nonewline for thefollowing output but was note get on one line. Can you please help.<\/p>\n
Foreach ($service in $services) { $Rservice = get-service -Name $service -computername CLPROD03<\/p>\n
If ($Rservice.status -eq ‘Running’) {<\/p>\n
Write-output The status for $Rservice.Displayname is $Rservice.status}<\/p>\n
}<\/p>\n
)<\/p>\n
The<\/p>\n
status<\/p>\n
for<\/p>\n
Integra: AUS - LP - CL Server<\/p>\n
is<\/p>\n
Running<\/p>\n
The<\/p>\n
status<\/p>\n
for<\/p>\n
Integra: AUS - LP - PD Server<\/p>\n
is<\/p>\n
Running<\/p>\n
The<\/p>\n
status<\/p>\n
for<\/p>\n
Integra: AUS - LP - RF Server<\/p>\n
is<\/p>\n
Running<\/p>\n
Foreach ($service in $services) { $Rservice = get-service -Name $service -computername CLPROD03\n If ($Rservice.status -eq 'Running') {\n Write-output The status for $Rservice.Displayname is $Rservice.status}\n }\n)\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-03-31T18:31:54.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/9","author":{"@type":"Person","name":"sunny75","url":"https://community.spiceworks.com/u/sunny75"}},{"@type":"Answer","text":"no-newline works with write host, if you want to display all in single line<\/p>\n
$services=@('Windows Time' \n'Windows Update Medic Service' \n'Windows Connection Manager' \n'Diagnostic Service Host'\n)\nForeach ($service in $services){\n$check=get-service -computername CLPROD03 -DisplayName \"$service\"\n If ($check.status -eq 'Running')\n {\n Write-Host \"The status for $($check.Displayname) is $($check.status), \" -NoNewline\n }\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-04-01T01:25:20.000Z","url":"https://community.spiceworks.com/t/get-service-output-not-working-as-it-shoud/795562/10","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}}]}}
Neally
(Neally)
March 31, 2021, 3:32pm
2
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…