Services and service accounts

Once you have identified the instances, you may want to know the SQL Server-related services for each one of the instances. You can use the same SMO class to query the services related to a SQL Server instance. The Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer class has a property called Services that lists the services:

Import-Module SQLPS -DisableNameChecking

#current server name
$servername = "ROGUE"

$managedComputer = New-Object "Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer" $servername

$managedComputer.Services |
Select-Object Name, ServiceAccount, DisplayName |
Format-Table -AutoSize

You should see a result similar to the following screenshot:

You can see that in my instance, I have many services ...

Get PowerShell for SQL Server Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.