Removing Organizational Units
Removing Organizational Units
Removes the specified Organizational Unit(s).
Examples:
Hint: The execution of these examples requires a connected PowerShell drive. |
Remove the Organization Unit object "solys.local\Bukarest":
Remove-EmdbOrganizationalUnit "emdb:\rootDSE\Managed Users & Computers\solys.local\Bukarest" |
This removes the Organizational Unit "solys.local\Bukarest" in the current context:
Cd "emdb:\rootDSE\Managed Users & Computers\solys.local" Remove-EmdbOrganizationalUnit "Bukarest" |
Hint: Organization Units that have child objects, e.g. other Organizational Units or Computers, can not be deleted using only the cmdlet Remove-EmdbOrganizationalUnit. In this case the standard cmdlet Remove-EmdbOrganizationalUnit parametrised with the switch parameter -RecurseRemove has to be used. If the RecurseRemove parameter is omitted, PowerShell waits for an interactive confirmation of the deletion of every child object. |
Remove-EmdbOrganizationalUnit "Bukarest" -RecurseRemove |
As an alternative method, the following shows the removing of the Organizational Unit "solys.local\Bukarest" using the Delete()-method:
$MyOU = Get-EmdbOrganizationalUnit "emdb:\rootDSE\Managed Users & Computers\solys.local\Bukarest" $MyOU.Delete() |
Hint: Organizational Units that have child objects, e.g. other Organizational Units or Computers, can not be deleted using the method Delete(). In this case the standard cmdlet Remove-Item parametrised with the switch parameter -Recurse has to be used. If the switch parameter is omitted, PowerShell waits for an interactive confirmation of the deletion of every child object. |
Remove the Organizational Unit "solys.local\Rome" incl. its child objects using the cmdlet Remove-Item:
Remove-Item "emdb:\rootDSE\Managed Users & Computers\solys.local\Rome" -Recurse |
Hint: Alternatively the alias DEL can be used to remove Organizational Unit objects. |
Starting with PSX 3.1 there was a new option implemented when deleting Organizational Unit objects. When specifying the SingleItemExpected-switch it is expected, that none or exactly one object is affected. If the command would delete more than one object, an error is raised that can be caught and handled in scripts.