Hi folks,
This is a script that will help you creating OU infrastructure in the brand new Active Directory environment (of course it can also be used in creating OUs in existing AD, provided that you use OU names that are not in use). In addition to this it will protect newly created OUs from accidental deletion which is similar to this:
Make sure that you replace DC=contoso,DC=com with the right LDAP path of your domain and feel free to replace names for OUs (next to OU=) with the names that are in your environment
Import-Module ActiveDirectory
$objDomain =[ADSI]"LDAP://DC=contoso,dc=com "
$objOU = $objDomain.Create("organizationalUnit","ou=Clusters")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Servers")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Groups")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Security Groups,ou=Groups")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Distribution Groups,ou=Groups")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Services")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Staff")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Admins")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Workstations")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=SQL Servers,ou=Servers")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Exchange Servers,ou=Servers")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=Lync Servers,ou=Servers")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=CRM Servers,ou=Servers")
$objOU.SetInfo()
$objOU = $objDomain.Create("organizationalUnit","ou=BES Servers,ou=Servers")
$objOU.SetInfo()
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true
Enjoy
No comments:
Post a Comment