This could be my shortest post ever, with a simple “yes”, but let me elaborate.
At times, you have to restart a service. With Powershell, this is easy enough (provided you have the right permissions): Restart-Service -name will do the trick. But every now and again, you have to restart a service that has dependent services. Like WMI, or SQL Server. In that case, Powershell will raise an error:
For those who actually read error messages, this one is pretty clear: you have to use the -Force flag to restart a service with dependent services (actually only one in this case, but who’s counting?). But does that also restart the dependent services? The Services MMC does restart dependent services, but I don’t like guessing. Let’s find out.
The first place to look is in the help: Help Restart-Service -Full.
No answer here. So let’s test it. I’ll use the SQL Server service as an example, which has one dependent service: the SQL Server Agent service.First, let’s find out what the dependent service actually is. Get-service returns a service object with a property called Dependentservices; expanding that returns the required info.
1 2 |
Get-Service MSSQLSERVER | Select-Object -Expandproperty Dependentservices |
Now, let’s restart SQL Server:
1 |
Get-Service mssqlserver | Restart-Service -Force |
Now, the service will be restarted. You can hit the up arrow twice, and rerun the command to check the status of the dependent services. And there’s you’re answer: the dependent services are restarted as well.