Create Active Directory OU's with Powershell
Hallo zusammen,
Mich hat interessiert wie man mit Powershell AD OU's erstellen kann. Wie immer führen mehrere Wege zum Ziel.
Powershell
#******************************************************************************
# Create a Set of AD OU's with Powershell
#******************************************************************************
$NewOU = Read-Host "Enter New Organizational Unit (OU) Name"
$MainOU = [ADSI] "LDAP://OU=units,dc=ads,dc=int"
$ou = $MainOU.Create("OrganizationalUnit", "ou="+$NewOU)
$ou.SetInfo()
$UsersOU = [ADSI]($ou.psbase.path)
$newOU = $UsersOU.Create("OrganizationalUnit","ou=Users")
$newOU.SetInfo()
$ComputersOU = [ADSI]($ou.psbase.path)
$newOU = $ComputersOU.Create("OrganizationalUnit","ou=Computers")
$newOU.SetInfo()
$GroupsOU = [ADSI]($ou.psbase.path)
$newOU = $GroupsOU.Create("OrganizationalUnit","ou=Groups")
$newOU.SetInfo()
Powersehell und AD Module
#******************************************************************************
# Create a Set of AD OU's with Powershell and AD Module
# http://blog.icewolf.ch/archive/2010/10/18/AD-Module-for-Powershell.aspx
#******************************************************************************
Import-Module ActiveDirectory
$NewOU = Read-Host "Enter New Organizational Unit (OU) Name"
$BaseOU = Get-ADOrganizationalUnit "OU=units,DC=ads,DC=int"
New-ADOrganizationalUnit -name $NewOU -path $BaseOU
$MainOUstr = "OU=" + $NewOU + "," + $BaseOU
$MainOU = Get-ADOrganizationalUnit $MainOUstr
New-ADOrganizationalUnit -name "Users" -path $MainOU
New-ADOrganizationalUnit -name "Computers" -path $MainOU
New-ADOrganizationalUnit -name "Groups" -path $MainOU
Powershell und Quest Activeroles
#******************************************************************************
# Create a Set of AD OU's with Powershell and Quest Activeroles
# http://blog.icewolf.ch/archive/2010/12/02/Quest-ActiveRoles-Management-Shell-for-Active-Directory.aspx
#******************************************************************************
Add-PSSnapin quest.activeroles.admanagement
$NewOU = Read-Host "Enter New Organizational Unit (OU) Name"
$MainOU = New-QADObject -ParentContainer "OU=units,dc=ads,dc=int" -Name $newOU -Type organizationalUnit
$UsersOU = New-QADObject -ParentContainer $MainOU -Name "Users" -Type organizationalUnit
$ComputersOU = New-QADObject -ParentContainer $MainOU -Name "Computers" -Type organizationalUnit
$GroupsOU = New-QADObject -ParentContainer $MainOU -Name "Groups" -Type organizationalUnit
Und so sieht das Resultat aus.
Das ganze geht aber auch interaktiv mit dem AD Module
Import-Module ActiveDirectory
cd AD:
cd "DC=ads,DC=int"
dir
cd "OU=Units"
dir
md "OU=UnitX"