KySoto

importusersv2.ps1

Jan 12th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Users = Import-Csv -Delimiter "," -Path ".\test.csv"  
  2. foreach ($User in $Users)  
  3. {  
  4. # username is structured lastname, firstname
  5.     $FIRST = $User.Name.substring(($User.Name.indexof(',')+2))
  6.     $LAST = $User.Name.substring(0,$User.Name.indexof(','))
  7.     $UPN = $FIRST + '.' + $LAST + '@IT-network.local'
  8.     $SAM = $FIRST + '.' + $LAST #20 char max
  9.     if( $SAM.length -gt 20)#truncates for names over the limit
  10.     {
  11.     $SAM = $SAM.substring(0,20)
  12.     }
  13.     $WHOLE = $FIRST + ' ' + $LAST
  14.     #password takes everything after the first character
  15.     $PW = $user.Password.substring(1)
  16.     New-ADUser -Name $WHOLE -SamAccountName $SAM -UserPrincipalName $UPN -DisplayName $WHOLE -GivenName $FIRST -Surname $LAST -AccountPassword (ConvertTo-SecureString $PW  -AsPlainText -Force) -Enabled $true -Path "OU=Have class,OU=Students,DC=IT-network,DC=local" -server itserver.IT-network.local
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment