Linked Questions

Popular Questions

Delete expired accounts in specific OUs

Asked by At

Trying to make a PS script that finds and deletes expired accounts in specific OUs

I've created this script, and it gets the users that is expired in the 4 OUs, so far so good, but I cant get my head around how to make it delete the users.

$OUs=
"OU=1,OU=Users,DC=Test,DC=local",
"OU=2,OU=Users,DC=Test,DC=local",
"OU=3,OU=Users,DC=Test,DC=local",
"OU=4,OU=Users,DC=Test,DC=local"

Foreach($OU in $OUs){
Search-ADAccount -AccountExpired -Searchbase $OU | Select-Object Name
}

Anybody that got a solution for this? :)

Related Questions