Status Name DisplayName PSComputerName
------ ---- ----------- --------------
Running MSSQL$SQLEXPRESS SQL Server (SQLEXPRESS) 192.168.160.1
Running SQLBrowser SQL Server Browser 192.168.160.1
Running SQLTELEMETRY$SQ... SQL Server CEIP service (SQLEXPRESS) 192.168.160.1
Running SQLWriter SQL Server VSS Writer 192.168.160.1
Now I want to get the word “Running”, so I can create an if statement, if the service is not running, to start it. So I change the command to this
Since services with a startup type of Disabled wouldn’t start at all you have to check the startup type as well before you try to restart a service.
Often it is easier to inspect an object just by looking at its properties and ignore its methods at first. So you could run this:
Get-Service |
Select-Object -Property * -First 1
Now you see all available properties of the first service on the machine you ran this command.
Now that you know the properties you could filter for services with the startuptype “Automatic” but with a status of “Stopped”. (For better readability we select only 4 properties to display)
Now you can replace the Select-Object command with a loop and restart all services you want to be restarted. Of course you can use the same conditions used here for the Where-Object for an if statement inside a loop if you want.
When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.
Thanks
I highly recommend to you to do a big step back and start with learning the very basics of PowerShell first. That will save you from a lot of wasted time and frustrations. And it will enable you to actually understand the help you get in forums like this. You cannot learn a complex technology like a scripting language by piecing togehter seom arbitrary peieces of code you’va found on the internet.