Managing Active Directory (AD) service accounts is essential for securing automated processes, applications, and services that require domain authentication. IT admins often need to retrieve details of these accounts to audit permissions, monitor usage, and ensure compliance with security policies. While the Get-ADServiceAccount PowerShell command allows admins to fetch information about managed service accounts, it often requires extensive scripting.
Before running the Get-ADServiceAccount cmdlet, ensure the following requirements are met:
Install-WindowsFeature -Name RSAT-AD-PowerShell
Import-Module ActiveDirectory
Use the Get-ADServiceAccount cmdlet to retrieve managed service accounts. The syntax is as follows:
Get-ADServiceAccount
[-AuthType <ADAuthType>]
[-Credential <PSCredential>]
[-Identity] <ADServiceAccount>
[-Partition <String>]
[-Properties <String[ ]>]
[-Server <String>]
[<CommonParameters>]
Example 1: Get a filtered list of managed service accounts
Get-ADServiceAccount -Filter "HostComputers -eq 'CN=SQL-Server-1, DC=contoso,DC=com'"
Enabled : True
Name : service1
UserPrincipalName :
SamAccountName : service1$
ObjectClass : msDS-ManagedServiceAccount
SID : S-1-5-21-159507390-2980359153-3438059098-29770
ObjectGUID : eaa435ee-6ebc-44dd-b4b6-dc1bb5bcd23a
HostComputers : {CN=SQL-Server-1, DC=contoso,DC=com}
DistinguishedName : CN=service1,CN=Managed Service Accounts,DC=contoso,DC=com
Example 2: Get a managed service account using the Security Account Manager name
Get-ADServiceAccount -Identity service1
Enabled : True
Name : service1
UserPrincipalName :
SamAccountName : service1$
ObjectClass : msDS-ManagedServiceAccount
SID : S-1-5-21-159507390-2980359153-3438059098-29770
ObjectGUID : eaa435ee-6ebc-44dd-b4b6-dc1bb5bcd23a
HostComputers :
DistinguishedName : CN=service1,CN=Managed Service Accounts,DC=contoso,DC=com
The table below lists key parameters that can be used with the Get-ADServiceAccounts cmdlet to get AD service accounts efficiently.
| Parameters | Description |
|---|---|
| -AuthType | This specifies the authentication method to use. |
| -Credential | This specifies the user account credential to use to perform this task. |
| -Filter | This specifies a query string that retrieves AD objects. |
| Identity | This specifies an AD account object by giving one of the following property values:
|