PowerShell Logo Small

Remove-ADObject



This is the built-in help made by Microsoft for the command 'Remove-ADObject', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Removes an Active Directory object.

SYNTAX


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



Search powershellhelp.space

DESCRIPTION


The Remove-ADObject cmdlet removes an Active Directory object. You can use this cmdlet to remove any type of Active Directory object.


The Identity parameter specifies the Active Directory object to remove. You can identify an object by its distinguished name (DN) or GUID. You can also set the Identity
parameter to an Active Directory object variable, such as $<localObject>, or pass an object through the pipeline to the Identity parameter. For example, you can use the
Get-ADObject cmdlet to retrieve an object and then pass the object through the pipeline to the Remove-ADObject cmdlet.


If the object you specify to remove has child objects, you must specify the Recursive parameter.


For AD LDS environments, the Partition parameter must be specified except when:

-- Using a DN to identify objects: the partition will be auto-generated from the DN.
-- Running cmdlets from an Active Directory provider drive: the current path will be used to set the partition.
-- A default naming context or partition is specified.


To specify a default naming context for an AD LDS environment, set the msDS-defaultNamingContext property of the Active Directory directory service agent (DSA) object
(nTDSDSA) for the AD LDS instance.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=291090
Get-ADObject
New-ADObject
Set-ADObject

REMARKS

<

Examples


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

PS C:\>Remove-ADObject -Identity 'CN=AmyAl-LPTOP,CN=Computers,DC=FABRIKAM,DC=COM'
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target "CN=AmyAl-LPTOP,CN=Computers,DC=FABRIKAM,DC=COM".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y



This command removes the object identified by the DistinguishedName CN=AmyAl-LPTOP,CN=Computers,DC=FABRIKAM,DC=COM.




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

PS C:\>Remove-ADObject -Identity "OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM" -Recursive
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target "OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y



This command deletes the container with DistinguishedName OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM including the child objects. Note: All the children of the container
including the ones which are protected from accidental deletion are also deleted.




-------------------------- EXAMPLE 3 --------------------------

PS C:\>Remove-ADObject -Identity "65511e76-ea80-45e1-bc93-08a78d8c4853" -Confirm:$False



This command removes the object with objectGUID 65511e76-ea80-45e1-bc93-08a78d8c4853 without giving the confirmation prompt.




-------------------------- EXAMPLE 4 --------------------------

PS C:\>Remove-ADObject -Identity "CN=InternalApps,DC=AppNC" -Server "FABRIKAM-SRV1:60000"
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target "CN=InternalApps,DC=AppNC".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y



This command removes the object with DistinguishedName CN=InternalApps,DC=AppNC from an LDS instance.




-------------------------- EXAMPLE 5 --------------------------

PS C:\>Get-ADObject -Filter 'isDeleted -eq $true -and -not (isRecycled -eq $true) -and name -ne "Deleted Objects" -and lastKnownParent -eq
"OU=Accounting,DC=Fabrikam,DC=com"' -IncludeDeletedObjects | Remove-ADObject



This command recycles all the objects in the recycle bin which used to be in the container OU=Accounting,DC=Fabrikam,DC=com.