Loop through servers and check services status

aristosv,
Welcome back to the forum. :wave:t4: … long time no see.

Why do you use if statements for that? … and BTW:

In PowerShell the equal sign (=) is the assignment operator. If you want to check for equality you should use -eq. :point_up_2:t4:

Why do you think you need a function? … and BTW: Set-Service is used to change the settings of a given service - not to start or restart it. Therefor you should use Start-Service or Restart-Service.

I’d recommend to save the needed information in a structured way - for example a CSV file. Thhen you can iterate with a nested loop of the servers and for each server over the services.

In general: what you’re asking for is a very common and simple task what has been asked a lot of times and already answered a lot of time. You don’t have to re-invent the wheel again. Use your prefered internet search engine to search for examples you can adapt to your particular needs. You will find some even here on PowerShell.org.

Here you have some examples: