Check if OU exists before creating it

Question:


This is my script, the purpose of which is to create a OU unless it already exist. I just can’t figure out what’s wrong with my code.

Answer:

Simply check if Get-ADOrganizationalUnit returns an OU with that distinguished name and create it otherwise:

Source:

Check if OU exists before creating it by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply