| Author |
Topic  |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 11/27/2012 : 09:22:48 AM
|
Hello, I have a need to create about 700 test accounts in AD for performance testing that involves an Oracle application using AD as the information source for users and assigning responsibilites based on certain attribute values. That being said, I have tried to generate a PoSh script with the following goals: 1. Create the user from information in a CSV file. 2. Set the password. 3. Enable the account. 4. Set an expirataion date on the account for later this year.
$objOU=[ADSI]“LDAP://OU=Users,OU=Testing,DC=domain,DC=com” $dataSource=import-csv “UserSpreadTest.csv” foreach($dataRecord in $datasource) { $cn=$dataRecord.sn + ”, ” + $dataRecord.givenName $sAMAccountName=$dataRecord.samAccountName $givenName=$dataRecord.givenName $sn=$dataRecord.sn $sAMAccountName=$sAMAccountName.ToLower() $displayName=$sn + “, ” + $givenName $userPrincipalName=$sAMAccountName + “@domain.com” $mail=$sAMAccountName + “@domain.com” $dt = [datetime] "12/31/2012 5:00pm" $objUser=$objOU.Create(“user”,”CN=”+$cn) $objUser.Put(“sAMAccountName”,$sAMAccountName) $objUser.Put(“userPrincipalName”,$userPrincipalName) $objUser.Put(“displayName”,$displayName) $objUser.Put(“givenName”,$givenName) $objUser.Put(“sn”,$sn) $objUser.Put(“accountexpires”,$dt) $objUser.SetInfo() $objUser.SetPassword(“IworkT0Live!!”) $objUser.psbase.InvokeSet(“AccountDisabled”,$false) $objUser.SetInfo() }
UserSpreadTest.csv sn, givenName, mail, userPrincipalName, cn, samAccountName, Password, Description PTESS, User1, PTESSUser1@domain.com, PTESSUser1@domain.com, PTESS, User1, PTESSUser1, IworkT0Live!!, Account used for performance testing of the Voyager UAT environment to be concluded by 12/31/2012. Owner: Sixpack, Joe
Needless to say, this isnt' working. The first error indicates that "an invalid DN syntax has been specified on line 19" ($objUser.Put(“accountexpires”,$dt) and "the directory property cannot be found on line 21" ($objUser.SetPassword(“IworkT0Live!!”). I know I must be missing something basic here; I'm used to VBScripting but really want to focus on PowerShell going forward. I'll keep digging in the meantime but wanted to post here and get some insight.
Thanks in advance.
|
Edited by - Edwardthe1st on 11/27/2012 09:29:36 AM |
|
|
ledson
Major Contributor
   
USA
1196 Posts
Status: offline |
Posted - 11/27/2012 : 1:29:19 PM
|
Here's the powershell equiv:
Import-Csv 'userspreadtest.csv' | New-ADUser -SamAccountName $_.Alias -UserPrincipalName $_.UPN -Name $_.Name -DisplayName $_.Name -GivenName $_.FName -Surname $_.LName -Path $_.OU -Department $_.Department -StreetAddress $_.streetaddress -City $_.city -State $_.state -PostalCode $_.postalcode -Office $_.office -AccountPassword (ConvertTo-SecureString "IworkT0Live!!" -AsPlainText -Force) -Enabled $true -PasswordNeverExpires $false -PassThru } > Import.log
The $_.whatever variables indicate a column (with the correct headers) needed for your csv file. You can change the name of the variables to match your current file, and remove the options you don't need. (Such as -StreetAddress, -PostalCode, etc.)
Luke Edson |
CCIE, CISSP, MCITP:Lync,Exchange,AD, MCSE:Communication (Lync 2013) |
 |
|
|
wkasdo
Administrator
    
Netherlands
7405 Posts
Status: offline |
Posted - 11/27/2012 : 3:02:24 PM
|
I haven't analysed the thing in detail, but this looks wrong:
$cn=$dataRecord.sn + ”, ” + $dataRecord.givenName
If you have a "," in a DN component, you need to escape it. Otherwise it looks like you are splitting the DN! |
Make it as simple as you can, but not simpler -- Albert Einstein |
 |
|
| |
Topic  |
|
|
|