Created
June 7, 2017 06:11
-
-
Save marckean/56c665b9d7286eac0700831068d1ce97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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