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:

  1. Open PowerShell ISE as an administrator.
  2. Import the SQLPS module as follows:
    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. 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 ...

Get SQL Server 2014 with PowerShell v5 Cookbook 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.