Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Users = Import-Csv -Delimiter "," -Path ".\test.csv"
- foreach ($User in $Users)
- {
- # username is structured lastname, firstname
- $FIRST = $User.Name.substring(($User.Name.indexof(',')+2))
- $LAST = $User.Name.substring(0,$User.Name.indexof(','))
- $UPN = $FIRST + '.' + $LAST + '@IT-network.local'
- $SAM = $FIRST + '.' + $LAST #20 char max
- if( $SAM.length -gt 20)#truncates for names over the limit
- {
- $SAM = $SAM.substring(0,20)
- }
- $WHOLE = $FIRST + ' ' + $LAST
- #password takes everything after the first character
- $PW = $user.Password.substring(1)
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment