Version: 5.1.x
Let’s explore a little bit the Get-Service PowerShell cmdlet. Recently I needed to look for specific windows services and check their status. In this post, I’ll try to share this experience and easily show a way to monitor and get this information.
During this post, I’ll be doing my examples on Visual Studio Code with an extension to interpret PowerShell scripts. I like to use this editor, but feel free to attempt on Windows ISE, the only thing that you’ll need to take care of is to run one or the other as administrator to avoid permission issues.
Let’s see how the cmdlet works and what we can do with it… Firstly, just run it alone without adding any parameters and see what you get.
#getting all the services from the machine you're running the script
Get-Service
Even if the sort is made by a different column you can easily verify that the result is the one that you’re expecting by executing the services from windows.
You already know what we can get from the cmdlet but now how can you refine your results? Let’s attempt to get some extra info from the helper.
As we can realize from our helper query, the cmdlet allows us to send some parameters to refine our results. Besides that, and this may be very helpful, you can also get the result not only from your Local Computer but also from a Remote Computer.
Our example will pass only throw executing the script targeting a Local Computer but we’ll also add on it the – ComputerName just for testing purposes.
A new attempt to refine our results.
#Filtering the services - refining the results
Get-Service -ComputerName 'PTPOPF247203' -DisplayName '*Hyper-V*'
What we’ll get now are all the services that have on its – DisplayName the “Hyper-V” word.
Now you are seeing the target you aimed, but well, imagine that this task was asked by someone that is not interested in the ugly name that the services have… How we can display only the columns that we want!? The next code will help.
#Filtering the services - refining the results
Get-Service -ComputerName 'PTPOPF247203' -DisplayName '*Hyper-V*' |
Select DisplayName,Status
And the result is…
Now looks much more interesting… As you see with some refining and using the Select PowerShell cmdlet we were able to query some useful data from our local machine.
Because nothing else can get you faster on the track… Do it by yourself on your Local or Remote Machine and let us know the results.
Top comments (0)