Removing Organizational Units

Removes the specified Organizational Unit(s).


Examples:


Hint: The execution of these examples requires a connected PowerShell drive.


Remove the  Organizational Unit "Virtual Environments\ESXServers" using the method Delete():


$MyOU = Get-EmdbOrganizationalUnit "emdb:\rootDSE\Managed Virtual Environments\ESXServers"

$MyOU.Delete()


Hint:  Organizational Units that have child objects, e.g. other Organizational Units or Virtualization Hosts, 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 "Virtual Environments\Other" incl. its child objects using the cmdlet Remove-Item:


Remove-Item "emdb:\rootDSE\Managed Virtual Environments\Other" -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.