Uninstall-ADServiceAccount

Uninstall-ADServiceAccount

Uninstalls an Active Directory service account from a computer.

Syntax

Uninstall-ADServiceAccount [-Identity] <ADServiceAccount> [-AuthType {<Negotiate> | <Basic>}] [-Confirm] [-WhatIf] [<CommonParameters>]
  • Identity

  • AuthType

  • Confirm

  • WhatIf

Detailed Description

The Uninstall-ADServiceAccount cmdlet removes an Active Directory service account on the computer on which the cmdlet is run. The specified service account must be installed on the computer.

The Identity parameter specifies the Active Directory service account to uninstall. You can identify a service account by its distinguished name (DN), GUID, security identifier (SID), or Security Accounts Manager (SAM) account name. You can also set the parameter to a service account object variable, such as $<localServiceAccountObject> or pass a service account object through the pipeline to the Identity parameter. For example, you can use the Get-ADServiceAccount to get a service account object and then pass that object through the pipeline to the Uninstall-ADServiceAccount cmdlet.

Parameters

AuthType

Specifies the authentication method to use. Possible values for this parameter include:
Negotiate or 0
Basic or 1

The default authentication method is Negotiate.

A Secure Sockets Layer (SSL) connection is required for the Basic authentication method.

The following example shows how to set this parameter to Basic.
-AuthType Basic

The following lists the acceptable values for this parameter:

  • Negotiate**

  • Basic**

Default Value: Microsoft.ActiveDirectory.Management.AuthType.Negotiate

Data Type: ADAuthType

Attributes

Name Value PSMAML Attribute

Required?

false

required

Variable Length?

false

variableLength

Accept wildcard characters?

false

globbing

Accept Pipeline Input?

false

pipelineInput

Position?

named

position

Value Attributes

Name Value PSMAML Attribute

Required?

true

required

Variable Length?

false

variableLength

Identity

Specifies an Active Directory account object by providing one of the following property values. The identifier in parentheses is the LDAP display name for the attribute.

Distinguished Name
Example: CN=WebAccount,CN=ManagedServiceAccounts,DC=corp,DC=contoso,DC=com
GUID (objectGUID)
Example: 599c3d2e-f72d-4d20-8a88-030d99495f20
Security Identifier (objectSid)
Example: S-1-5-21-3165297888-301567370-576410423-1103
SAM Account Name (sAMAccountName)
Example: WebAccount$

The cmdlet searches the default naming context or partition to find the object. If two or more objects are found, the cmdlet returns a non-terminating error.

This parameter can also get this object through the pipeline or you can set this parameter to an object instance.

This example shows how to set the parameter to a distinguished name.
-Identity "CN=WebAccount,CN=ManagedServiceAccounts,DC=corp,DC=contoso,DC=com"

This example shows how to set this parameter to an account object instance named "AccountInstance".
-Identity $AccountInstance

Default Value: **

Data Type: ADServiceAccount

Attributes

Name Value PSMAML Attribute

Required?

true

required

Variable Length?

false

variableLength

Accept wildcard characters?

false

globbing

Accept Pipeline Input?

true (ByValue)

pipelineInput

Position?

1

position

Value Attributes

Name Value PSMAML Attribute

Required?

true

required

Variable Length?

false

variableLength

Confirm

Prompts you for confirmation before executing the command.

Default Value: **

Data Type: SwitchParameter

Attributes

Name Value PSMAML Attribute

Required?

false

required

Variable Length?

true

variableLength

Accept wildcard characters?

false

globbing

Accept Pipeline Input?

false

pipelineInput

Position?

named

position

Value Attributes

Name Value PSMAML Attribute

Required?

false

required

Variable Length?

false

variableLength

WhatIf

Describes what would happen if you executed the command without actually executing the command.

Default Value: **

Data Type: SwitchParameter

Attributes

Name Value PSMAML Attribute

Required?

false

required

Variable Length?

true

variableLength

Accept wildcard characters?

false

globbing

Accept Pipeline Input?

false

pipelineInput

Position?

named

position

Value Attributes

Name Value PSMAML Attribute

Required?

false

required

Variable Length?

false

variableLength

Input Type

None or Microsoft.ActiveDirectory.Management.ADServiceAccount

A service account object is received by the Identity parameter.

Return Type

None

Notes

  • This cmdlet does not work with AD LDS.
    This cmdlet does not work with an Active Directory Snapshot.
    This cmdlet does not work with a read-only domain controller.

Examples

-------------------------- EXAMPLE 1 --------------------------

Command Prompt: C:\PS>

Uninstall-ADServiceAccount -Identity SQL-SRV1 
                           

Uninstall the service account SQL-SRV1 from the local machine.

-------------------------- EXAMPLE 2 --------------------------

Command Prompt: C:\PS>

$a = Get-ADServiceAccount -Filter { Name -eq 'SQL-HR-svc-01'}  
Uninstall-ADServiceAccount $a  
Remove-ADServiceAccount $a 

Search for the service account with named SQL-HR-svc-01 in the local machine. Uninstall this account and then delete it from the directory.

See Also

Reference

Get-ADServiceAccount
Install-ADServiceAccount
New-ADServiceAccount
Remove-ADServiceAccount
Set-ADServiceAccount

Other Resources

Online version: