Remove-ADOrganizationalUnit

Modify an Active Directory organizational unit.

Syntax
      Remove-ADOrganizationalUnit [-Identity] ADOrganizationalUnit
         [-AuthType {Negotiate | Basic}] [-Credential PSCredential]
            [-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 ADOrganizationalUnit
       An AD organizational unit object. Most often this will be a Distinguished Name (e.g. OU=demo,DC=SS64,DC=com)
       The identity may also be given as a GUID, Security Identifier or sAMAccountName.

       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 AD OU object may also be passed through the pipeline or set via a variable.

   -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 OU and any child items it contains.
       Specify this parameter to remove an OU that is not empty.
       This will remove all child objects even any that have been 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.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Remove-ADOrganizationalUnit removes an Active Directory Organizational Unit.

The -Identity parameter specifies the organizational unit to remove. Identify an organizational unit by its distinguished name (DN) or GUID. Alternatively set the -Identity parameter to an object variable or pass an object through the pipeline. e.g. from Get-adOrganizationalUnit

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

If the 'ProtectedFromAccidentalDeletion' property of the OU object is set to true, the cmdlet returns a terminating error.

Examples

Remove an OU and all of it's children.:

PS C:\> Remove-ADOrganizationalUnit -Identity "OU=Accounting,DC=SS64,DC=com" -Recursive

Removes an OU using it's objectGUID as the Identity while suppressing the confirmation prompt:

PS C:\> Remove-ADOrganizationalUnit -Identity "1b228aa5-2c14-48b8-ad8a-2685dc22e055" -confirm:$false

Remove the EaME OrganizationalUnit:

PS C:\> Remove-ADOrganizationalUnit -Identity "OU=EaME,DC=SS64,DC=com"

Remove an OU from an LDS instance:

PS C:\> Remove-ADOrganizationalUnit -Identity "OU=Managed,DC=AppNC" -server "SS64-SRV1:60000" -confirm:$false

“I never saw an oft-transplanted tree, Nor yet an oft-removed family, That throve so well as those that settled be” ~ Benjamin Franklin

Related:

Get-adOrganizationalUnit - Get one or more AD OUs
New-adOrganizationalUnit - Create a new AD OU
Set-adOrganizationalUnit - Modify an AD OU


© Copyright SS64.com 1999-2014
Some rights reserved