I am pretty green at Powershell and if this is simple, I apologize. I have tried to use this example script from user Nick, and run into an error I thought AdObject was supposed to go around. My Script
Import-Module ActiveDirectory
$list = Import-CSV C:\scripts\deletebulkusers.csv
forEach ($item in $list) {
$samAccountName = $item.samAccountName
#Get DistinguishedName from SamAccountName
$DN = Get-ADuser -Identity $Samaccountname -Properties DistinguishedName |
Select-Object -ExpandProperty DistinguishedName
#Remove object using DN
Remove-ADObject -Identity $DN
}
I have posted my error below:
Remove-ADObject : The directory service can perform the requested operation only on a leaf object
At line:13 char:5
+ Remove-ADObject -Identity $DN -confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=<user>,DC=com:ADObject) [Remove-ADObject], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8213,Microsoft.ActiveDirectory.Management.Commands.RemoveADObject