Listing SQL Server service accounts
We will list service accounts in this recipe.
How to do it...
These are the steps to listing SQL Server service accounts:
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Add the following script and run:
#replace KERRIGAN with your instance name $instanceName = "KERRIGAN" $managedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $instanceName #list services $managedComputer.Services | Select Name, ServiceAccount, DisplayName, ServiceState | Format-Table -AutoSize
How it works...
A service account is an account created for the exclusive purpose of running a service. To list service accounts, we can use the Wmi.ManagedComputer
object:
$managedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $instanceName
The managedComputer
instance has...