Creating an OU using PowerShell

by Mitch Tulloch [Published on 8 July 2015 / Last Updated on 8 July 2015]

A tip on how to use PowerShell to create an OU provided that the OU doesn't already exist.

It's easy to use PowerShell to create a new organizational unit (OU) but how do you make sure first that an OU with that name doesn't already exist in your Active Directory environment?

Here's how you can do it where the OU name you want to check for is Sales

$ou = Get-ADOrganizationalUnit -Filter 'name -eq "Sales" ';

if ($ou -eq $null)

{

     New-ADOrganizationalUnit -name Sales;

}

Mitch Tulloch is an eleven-time recipient of the Microsoft Most Valuable Professional (MVP) award and a widely recognized expert on Windows Server and cloud computing technologies.  For more information see http://www.mtit.com.

See Also


The Author — Mitch Tulloch

Mitch Tulloch is a well-known expert on Windows Server administration and cloud computing technologies. He has published over a thousand articles on information technology topics and has written, contributed to or been series editor for over 50 books.

Featured Links