Listing SQL Server service accounts
We will list service accounts in this recipe.
How to do it...
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:
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 a Wmi.ManagedComputer
object:
$managedComputer = New-Object Microsoft.SqlServer.Management.Smo...