I am trying to delete multiple ou's, not in the same parent\child structure but multiple OU's next to each other. Example:
OU=legal,OU=department,DC=company,DC=com
OU=marketing,OU=department,DC=company,DC=com
OU=advertising,OU=department,DC=company,DC=com
I can delete a single OU out with protection using the following:
Get-ADOrganizationalUnit -Identity 'OU=legal,OU=department,DC=company,DC=com' |
Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru |
Remove-ADOrganizationalUnit -Confirm:$false
But I'm unsure of how to get it to work with a foreach and a text file. Any help would be greatly appreciated
First I created the text file "C:\Temp\OU's.txt". With all the OU's inside it.
Note the -WhatIf in the end like Bill_Stewart said, to make sure you only see what is about to happen! Remove it and all the OU's stated in the text file will be removed.