We will list service accounts in this recipe.
These are the steps for listing SQL Server service accounts:
Open PowerShell ISE as an administrator.
Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Add the following script and run:
#replace localhost with your machine name #make sure you open the appropriate firewall ports $instanceName = "localhost" $managedComputer = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $instanceName #list services $managedComputer.Services | Select-Object Name, ServiceAccount, ServiceState | Format-Table –AutoSize
You should see a list of services and their service accounts in a format like this: