$OU = 'OU=Test Users,DC=test,DC=local' | |
$primaryemaildomain = "demo.domain.com" | |
$secondaryemaildomain = "demo2.domain.com" | |
$users = Import-Csv C:\users\Administrator\Desktop\New-ADUser.csv | |
$users | ForEach-Object { | |
$Name = $_.givenname + " " + $_.surname | |
$UPN = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower() + "@" + $primaryemaildomain | |
$SamAccountName = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower() | |
#$secondaryaddress = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower() + "@" + $secondaryemaildomain | |
$password = $_.AccountPassword | |
New-ADUser ` | |
-GivenName $_.GivenName ` | |
-Surname $_.Surname ` | |
-Name $Name ` | |
-DisplayName $name ` | |
-SamAccountName $SamAccountName ` | |
-Description $_.Description ` | |
-UserPrincipalName $UPN ` | |
-Title $_.Title ` | |
-StreetAddress $_.StreetAddress ` | |
-City $_.City ` | |
-State $_.State ` | |
-Country $_.Country ` | |
-PostalCode $_.PostalCode ` | |
-OfficePhone $_.OfficePhone ` | |
-MobilePhone $_.MobilePhone ` | |
-Department $_.Department ` | |
-Office $_.Office ` | |
-Path $OU ` | |
-Enabled $True ` | |
-AccountPassword (ConvertTo-SecureString $password -AsPlainText -force) ` | |
-PasswordNeverExpires $True | |
$distinguishedName = "CN=" + $Name + "," + $ou | |
Set-ItemProperty -Path ad:\$distinguishedName -Name mailnickname -Value $SamAccountName | |
Set-ItemProperty -Path ad:\$distinguishedName -Name mail -Value $UPN | |
Set-ItemProperty -Path ad:\$distinguishedName -Name proxyaddresses -Value SMTP:$UPN | |
Set-ADUser $DistinguishedName -Add @{proxyaddresses="smtp:$secondaryaddress"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment