Hi All,
The following is the powershell code to create test users and default ou structure. It's quite basic script. But works wells. Requires little modification. However if you like you can put various controls and make it more intelligent. I will try to put more controls latter but right now it just serves the purpose for which i created this script.
################################
#PowerShell Script To Create OU Structure and Test Users for Lab Env
# By v-2nas v 0.1
################################
Clear
$StrOUName = Read-Host "Enter SiteName for Creating Default Organizational Unit (OU) Structure"
$objDomain = [ADSI]"ldap://dc=brs,dc=glk,dc=net/"
$objOU = $objDomain.Create("OrganizationalUnit", "OU=" + $StrOUName)
#$objOU = $objDomain.Create("OrganizationalUnit", "ou=" + $StrOUName)
$objOU.SetInfo()
Write-Host $StrOUName "OU Has Been Created."
write-host "Now creating Default OU Structure........."
#### Default OU Structure
$objDomain1 = [ADSI]"ldap://ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu1 = $objDomain1.Create("OrganizationalUnit", "ou=" + "Accounts")
$objOu1.SetInfo()
$objDomain2 = [ADSI]"ldap://ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu2 = $objDomain2.Create("OrganizationalUnit", "ou=" + "Computers")
$objOu2.SetInfo()
$objDomain3 = [ADSI]"ldap://ou=Accounts,ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu3 = $objDomain3.Create("OrganizationalUnit", "ou=" + "Users")
$objOu3.SetInfo()
$objDomain4 = [ADSI]"ldap://ou=Accounts,ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu4 = $objDomain4.Create("OrganizationalUnit", "ou=" + "Groups")
$objOu4.SetInfo()
$objDomain5 = [ADSI]"ldap://ou=Computers,ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu5 = $objDomain5.Create("OrganizationalUnit", "ou=" + "MemberServer")
$objOu5.SetInfo()
$objDomain6 = [ADSI]"ldap://ou=Computers,ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$objOu6 = $objDomain6.Create("OrganizationalUnit", "ou=" + "Workstation")
$objOu6.SetInfo()
Write-Host "Creating Test User Account......"
# Create Users
$users = import-csv usersData.csv
$container = [ADSI] "ldap://OU=Users,ou=Accounts,ou=$StrOUName,dc=brs,dc=glk,dc=net/"
$users | foreach {
$UserName = $_.UserName
$newUser = $container.Create("User", "cn=" + $UserName)
$newUser.Put("sAMAccountName", $UserName)
$newUser.SetInfo()
$newUser.psbase.InvokeSet('AccountDisabled', $false)
$newUser.SetInfo()
$newUser.SetPassword("xxxxx")
$newUser.put("description","Test User Account for lab testing")
$newUser.put("givenName", $userName)
$newUser.SetInfo()
}
No comments:
Post a Comment