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

Schannel Issue

Indexing Server

oclist /xml or /?