Come and Check our BETA Alpha version of Powershellcenter.net
Send me your comment to Powershell@powershellcenter.com

Synopsis

Uninstalls an Active Directory service account from a computer.

Syntax

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

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. The ForceRemoveLocal switch parameter allows you to remove the account from the local computer without failing the command if access to a writable DC is not available. This is required if you are uninstalling the managed service account from a server located in a segmented network or site (such as perimeter network or DMZ) with access only to a read-only domain controller (RODC). If you pass this parameter and the server has access to a writable DC, the account will also be un-linked from the computer account in Active Directory Domain Services. If this parameter is used, it is recommended that you run Remove-ADComputerServiceAccount cmdlet against a writable DC to reliably unlink the managed service account from the computer.

Parameters

-AuthType [<ADAuthType>]

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:

Required?   false
Position?   named
Default value?   Microsoft.ActiveDirectory.Management.AuthType.Negotiate
Accept pipeline input?   false
Accept wildcard characters?   false

-ForceRemoveLocal [<SwitchParameter>]

The ForceRemoveLocal switch parameter allows you to remove the account from the local computer without failing the command if access to a writable DC is not available. This is required if you are uninstalling the managed service account from a server located in a segmented network or site (such as perimeter network or DMZ) with access only to a read-only domain controller (RODC). If you pass this parameter and the server has access to a writable DC, the account will also be un-linked from the computer account in Active Directory Domain Services. If this parameter is used, it is recommended that you run Remove-ADComputerServiceAccount cmdlet against a writable DC to reliably unlink the managed service account from the computer.

Required?   false
Position?   named
Default value?  
Accept pipeline input?   false
Accept wildcard characters?   false

-Identity [<ADServiceAccount>]

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

Required?   true
Position?   1
Default value?  
Accept pipeline input?   true (ByValue)
Accept wildcard characters?   false

-Confirm [<SwitchParameter>]

Prompts you for confirmation before executing the command.

Required?   false
Position?   named
Default value?  
Accept pipeline input?   false
Accept wildcard characters?   false

-WhatIf [<SwitchParameter>]

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

Required?   false
Position?   named
Default value?  
Accept pipeline input?   false
Accept wildcard characters?   false

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

PS> Uninstall-ADServiceAccount -Identity SQL-SRV1

Uninstall the managed service account SQL-SRV1 from the local machine. This requires access to a writable DC.

EXAMPLE 2

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

Search for the managed service account with named SQL-HR-svc-01 in the local machine. Uninstall this account and then delete it from the directory. This requires access to a writable DC.

EXAMPLE 3

PS> Uninstall-ADServiceAccount -Identity SQL-SRV1 -ForceRemoveLocal

Uninstall the managed service account SQL-SRV1 from the local machine even if access to a writable DC is not available.

It is recommended that you run Remove-ADComputerServiceAccount cmdlet against a writable DC to reliably unlink the managed service account from the computer.