Use PowerShell to create ou’s in Active Directory

Just a quick follow up to my last post on creating users with PowerShell.

If you find yourself in the need of creating a basic ou structure in Active Directory you can of course do this with PowerShell as well.

Below is a quick sample that we use in our Hydration Kits and demo environments.


### Create Base OU Structure ###

$basedn = "dc=iwu,dc=infoworksuniversity,dc=com"
$city = "Stockholm"
$country = "SE"

New-ADOrganizationalUnit -Name "Infoworks University" -Path $basedn -City $city -Country $country -ProtectedFromAccidentalDeletion $false

$basedn = "ou=Infoworks University," + $basedn

New-ADOrganizationalUnit -Name "Accounts" -Path $basedn -City $city -Country $country -ProtectedFromAccidentalDeletion $false
New-ADOrganizationalUnit -Name "Computers" -Path $basedn -City $city -Country $country -ProtectedFromAccidentalDeletion $false
New-ADOrganizationalUnit -Name "Member servers" -Path $basedn -City $city -Country $country -ProtectedFromAccidentalDeletion $false
New-ADOrganizationalUnit -Name "Groups" -Path $basedn -City $city -Country $country -ProtectedFromAccidentalDeletion $false

m4s0n501

About The Author

No Comments

Leave A Reply