Adding organizational units to AD through powershell
Anatoly Mironov
Want to create some organizational structure in AD, I suppose it is specifically useful in a development environment, well the best solution is powershell then. Mastering Powershell by and Powershell.nu by Niklas Goude provide examples how to do this.
$domain = [ADSI]""
$ou = $domain.Create("organizationalUnit", "OU=Administration")
$ou.SetInfo()Be sure you write “organizationalUnit” in lower case. Otherwise you’ll get “Exception calling “SetInfo” with “0” argument(s): “The specified directory service attribute or value does not exist” when you invoke $ou.setinfo(). If you want to create an OU under another OU, just create $domain and specify the location:
$domain = [ADSI]"OU=Administration, dc=takana, dc=local"
$company = $domain.Create("organizationalUnit", "OU=Accounting")
$company.SetInfo()To save some other properties:
$ou.put("Description", "this is a dummy ou")
$ou.SetInfo()Update 2013-12-10
In PowerShell V3 you have a built-in cmdlet for doing that once you add the Active Directory role in your server. It simple as that:
New-ADOrganizationalUnit "Accounting" -Path "dc=takana, dc=local"