Import-Csv -path NewAdUserFromExcel.csv | foreach { # -WhatIf New-AdUser -name $_.Name -GivenName $_.GivenName -Surname $_.SurName -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -OtherAttributes @{'mail'=$_.Mail} -Accountpassword (ConvertTo-SecureString -String $_.Password -AsPlainText -Force) -Enabled $true -path $_.Path -Company $_.Company Add-ADGroupMember -Identity "VPN Access group" -Members $_.SamAccountName Add-ADGroupMember -Identity "GitAccess" -Members $_.SamAccountName Set-ADUser -Identity $_.SamAccountName -PasswordNeverExpires $true }
Name,GivenName,Surname,SamAccountName,UserPrincipalName,Mail,Path,Password,Company John Smith,John,Smith,jsmith,jsmith@example.com,sohn.smith@example.com,"OU=Department,OU=Users,DC=example,DC=com",c0mpl3xp4$$w0rd,Department