Removing AD objects
In order to remove AD user objects, we can use the Remove-ADUser cmdlet. We can find the complete syntax information using the following command:
Get-Command Remove-ADUser -Syntax
When using the cmdlet, we need to use a value for the -Identity parameter to specify the account. We can use a distinguished name, GUID, SID, or the SamAccountName value to identify the account. If it is an LDS environment, we need to define the object partition parameter too:
Remove-ADUser -Identity "dzhang"
The preceding command will remove the AD user object called dzhang from the directory. It will ask for confirmation before it removes the object.
This cmdlet can also be combined with the search query to find objects before removing them:
Get-ADUser -Filter {Name -like "Test1*"} | Remove-ADUser
In the preceding command, we search the entire directory for the user whose name starts with Test1 and then remove that user.
The Remove...