How do I delete a list of empty OUs?


hello,

i have large list of ous need deleted: we've verified they're empty , they're ready removed. i've searched , haven't found solutions bulk remove-adorganizationalunit list. below script removes protected status, doesn't delete ou. i've tried replacing variable $object $objitem, , deletes ou listed in bottom of text file.

the ous listed dns in text file.

$textfile = gc -path "c:\scripts\ou deletion\ou deletion list.txt"    foreach ($object in $textfile){  set-adorganizationalunit -identity $object -protectedfromaccidentaldeletion $false | remove-adorganizationalunit -confirm:$false}  

any tips?

did try on separate lines?

$textfile = gc -path "c:\scripts\ou deletion\ou deletion list.txt"  foreach ($object in $textfile){ set-adorganizationalunit -identity $object -protectedfromaccidentaldeletion $false remove-adorganizationalunit -identity $object -confirm:$false}



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...