Remove-ADObject

Remove an Active Directory object.

Syntax
      Remove-ADObject [-Identity] ADObject
         [-AuthType {Negotiate | Basic}] [-Credential PSCredential]
            [-IncludeDeletedObjects] [-Partition string] [-Recursive] [-Server string]
               [-Confirm] [-WhatIf] [CommonParameters]

Key
   -AuthType {Negotiate | Basic}
       The authentication method to use: Negotiate (or 0), Basic (or 1)
       A Secure Sockets Layer (SSL) connection is required for Basic authentication.

   -Credential PSCredential
       The user account credentials to use to perform this task.
       The default credentials are those of the currently logged on user unless the
       cmdlet is run from an Active Directory PowerShell provider drive.
       If the cmdlet is run from such a provider drive, the account associated with the drive is the default.

       Type a user name, such as "User64" or "Domain64\User64" or specify a
       PSCredential object such as one generated by Get-Credential 

       If a user name is specified, the cmdlet will prompt for a password.

   -Identity ADObject
       An AD object. Most often this will be a Distinguished Name (e.g. CN=sample1,OU=demo,DC=SS64,DC=com)
       The identity may also be given as a GUID.

       Derived types, such as the following are also accepted:
          [Microsoft.ActiveDirectory.Management.]
            ADGroup,ADUser,ADComputer,ADServiceAccount,ADFineGrainedPasswordPolicy,ADDomain

       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.

       The ADObject may also be passed through the pipeline or set via a variable.

   -IncludeDeletedObjects
       Retrieve deleted objects and the deactivated forward and backward links.
       When this parameter is specified, the cmdlet uses the following LDAP controls:
          Show Deleted Objects (1.2.840.113556.1.4.417)
          Show Deactivated Links (1.2.840.113556.1.4.2065)

       If this parameter is not specified, the cmdlet will not return or operate on deleted objects.

   -Partition string
       The distinguished name of an AD partition.
       string must be one of the naming contexts on the current directory server.
       The cmdlet searches this partition to find the object defined by the -Identity parameter.
       Examples:
         -Partition "CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"
         -Partition "CN=Schema,CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"

       In many cases, a default value will be used for -Partition if no value is specified.

   -Recursive
       Remove the object and any children it contains.
       This will remove all child objects even if there are objects marked
       with ProtectedFromAccidentalDeletion.
                 
   -Server string
       The AD Domain Services instance to connect to, this may be a Fully qualified domain name,
       NetBIOS name, Fully qualified directory server name (with or without port number)

   -Confirm
       Prompt for confirmation before executing the command.

   -WhatIf
       Describe what would happen if you executed the command without actually executing the command.

Remove-ADObject removes any type of AD object.

The -Identity parameter specifies the AD object to remove. Identify an object by its distinguished name (DN) or GUID. The -Identity parameter may also be set to an AD object variable or through the pipeline. e.g. from Get-adObject.

Examples

Remove an object identified by its DistinguishedName:

PS C:\> Remove-ADObject 'CN=workstation64,CN=Computers,DC=SS64,DC=COM'

Delete a container identified by its DistinguishedName including all child objects:

PS C:\> Remove-ADObject "OU=Finance,OU=Norway,DC=SS64,DC=COM" -Recursive

“You may write me down in history
With your bitter, twisted lies,
You may trod me in the very dirt
But still, like dust, I'll rise” ~ Maya Angelou

Related PowerShell Cmdlets

Get-adObject - Get one or more AD objects.
Move-adObject - Move an AD object or container to a different container or domain.
New-adObject - Create an AD object.
Rename-adObject - Change the name of an AD object.
Restore-adObject - Restore an AD object.
Set-adObject - Modify an AD object.


 
Copyright © 1999-2024 SS64.com
Some rights reserved