Check Service via PowerShell

Hello again. Today, I have had a task to check the status of a service on all my servers.

Since I didn´t have much time, I decided to make a quick and ugly script to check the status of the service.

So lets start.

First, we need to get all our computer names and put them in a .txt file. I will call this file computers.txt

After this is done, we can start writing the script.

First few lines are quite straightforward:

[php]$array =@()
$computernames = Get-Content "C:\_scripts\check_Service\computers.txt"[/php]

Next, we will run a foreach loop:

[php]foreach($computer in $computernames) {

gwmi win32_service -computername $computer -filter "Name=’Plug and Play’" -Property Name,StartMode,State,SystemName | select Name,StartMode,State,SystemName


In our foreach loop we have used WMI to look for a service, we took one computer name from variable $computers, filtered the service name and choose properties to display.

So it will give us server name, current start mode, state, and the server host name.

And that is it. pretty quick and pretty ugly 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Bitnami banner