From anon, 1 Month ago, written in Plain Text.
This paste will shuffle off the mortal coil in 1 Second.
Embed
  1. $users = Import-csv C:\import.csv
  2.  
  3. for each ($user in $users){
  4.   $username = $user.Username
  5.   $password = $user.Password
  6.   $fname = $user.GivenName
  7.   $lname = $user.Surname
  8.   $occ = $user.Occupation
  9.  
  10.   if (Get-ADUser -F {SamAccountName -eq $Username}) {
  11.     Write-Warning "User: $Username exists."
  12.   } else {
  13.     New-ADUser `
  14.     -SamAccountName $username `
  15.     -UserPrincipalName "$username@pompeii.net" `
  16.     -Name "$fname $lname" `
  17.     -GivenName $fname `
  18.     -Surname $lname `
  19.     -Enabled $True `
  20.     -DisplayName "$lname, $fname" `
  21.     -Department $occ `
  22.     -Path $OU `
  23.     -AccountPassword (convertto-securestring $password -AsPlainText -Force)
  24.   }
  25. }