Question about Services Output

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Sigfreid Sigfreid 2 weeks, 4 days ago.

  • Author
    Posts
  • #58072
    Profile photo of Sigfreid
    Sigfreid
    Participant

    Hi,

    Good day! I'm new to Powershell and trying a few things.

    Can anyone help me show Stopped Services and the output would be like:

    (WinRM is Stopped) – something like this.

    I use the below syntax but I need to show the name of the service and some sort of output beside it hence I put in the write-host "is Stopped" thinking that it will show the name of the service and the output "is Stopped" beside.

    Get-Service * | Where-Object {$_.Status -eq "Stopped"}
    Write-host "is Stopped"

    Any help would be appreciated 🙂

  • #58076
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Hmmm ... in my opinion that does not look good ... but you asked ...

    Get-Service | Where-Object -Property Status -EQ -Value Stopped | Select-Object -Property Name,@{Name='is';Expression={'is'}},Status
    Get-Service | Where-Object -Property Status -EQ -Value Stopped | Select-Object -Property @{Name='Stopped Services';Expression={"$($_.Name)  is  $($_.Status)"}}
    • #58081
      Profile photo of Sigfreid
      Sigfreid
      Participant

      Thanks Olaf looks very good and shows the name and status.. So basically we created a some sort of Property name to show the word "Is" right?

      I was told that it should show the name of the service (running or stopped) and just some sort of output beside it. It look simple when my pal gave me the assignment to practice but looks like it is not that simple after all. Lol

      Sorry Olaf I just starting out and its just been 2 days 🙁 Just finished the CVT's, reading books so need more practice.

    • #58084
      Profile photo of Olaf Soyk
      Olaf Soyk
      Participant

      No need to sorry ... that's what we're all here for. To learn and to help. 😀

      Yes, it's called calculated properties. It's one way to change the output to your requirements.

      Usually there are several ways to accomplish a task. Another way could be this:

      Get-Service | Where-Object -Property Status -EQ -Value Stopped | ForEach-Object -Process {"$($_.Name) is $($_.Status)"}

      If you need more 'input' you will find some here: Beginner Sites And Tutorials 😀

  • #58100
    Profile photo of Stuart Squibb
    Stuart Squibb
    Participant

    There's always more than one day to do it:

    Get-Service | Where-Object -Property Status -Eq Stopped | ForEach-Object { Write-Host "$($PSItem.Name) is Stopped" }
    
  • #58148
    Profile photo of Sigfreid
    Sigfreid
    Participant

    Thanks a bunch Olaf and Stuart much much appreciated 🙂

    Have a nice weekend guys!

You must be logged in to reply to this topic.