PowerShell to delete all users in particular OU'S

#PowerShell to delete all users in particular OU'S

$search="OU=Testing,DC=pugazh, DC=co,DC=in"
$deletes= Get-ADUser -SearchBase $search -filter * -properties SamAccountName | Select-Object SamAccountName
$numusers=($deletes.count)
echo "$numusers Users Found"
foreach ($delete in $deletes)
{
   echo "Deleting user account $delete . . . "
remove-aduser -identity $delete.SamAccountName -confirm:$false
 }

Comments

Popular posts from this blog

Troubleshooting Netlogon Error Codes

Service Principal Names (SPNs) SetSPN Syntax (Setspn.exe)

Troubleshooting AD Active Directory Replication Error 8456 or 8457: "The source | destination server is currently rejecting replication requests"