Removing Domain Objects

Remove the specified domain object(s).


Examples:


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


Remove the domain object "solys.local\Beijing":


Remove-EmdbDomain "emdb:\rootDSE\Managed Users & Computers\solys.local\Beijing"


Remove the domain object "solys.local\Beijing" in the current context:


Cd "emdb:\rootDSE\Managed Users & Computers\solys.local"

Remove-EmdbDomain "Beijing"


Hint: Domain objects that have child objects, e.g. Organizational Units or Computers, can not be deleted using only the cmdlet Remove-EmdbDomain. In this case the standard cmdlet Remove-EmdbDomain 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-EmdbDomain "Beijing" -RecurseRemove


As an alternative method, the following shows the removing of the domain object "solys.local\Beijing" using the Delete()-method:


$MyDomain = Get-EmdbDomain "emdb:\rootDSE\Managed Users & Computers\solys.local\Beijing"

$MyDomain.Delete()


Hint: Domain objects that have child objects, e.g. 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 domain object "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 domain objects.


Starting with PSX 3.1 there was a new option implemented when deleting Domain 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.