Created
October 8, 2015 08:17
-
-
Save Grimthorr/2d85f4fda1b7f7408ffe to your computer and use it in GitHub Desktop.
PowerShell script to batch create (or import) users in Active Directory.
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
Import-Module ActiveDirectory | |
$Users = Import-Csv -Delimiter "," -Path ".\users.csv" | |
foreach ($User in $Users) { | |
$SAM = $User.Username | |
$Displayname = $User.Displayname | |
$Firstname = $User.Firstname | |
$Lastname = $User.Lastname | |
$OU = $User.Container | |
$UPN = $User.Username + "@contoso.com" | |
$Password = (ConvertTo-SecureString $User.Password -AsPlainText -Force) | |
New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName "$SAM" -UserPrincipalName "$UPN" -GivenName "$Firstname" -Surname "$Lastname" -AccountPassword $Password -Enabled $true -Path "$OU" -ChangePasswordAtLogon $false -PasswordNeverExpires $true | |
Write-Host "Created user: $SAM" | |
} |
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
Username | Displayname | Firstname | Lastname | Password | Container | |
---|---|---|---|---|---|---|
testuser | Test User | Test | User | Password1 | OU=Test,OU=Users,DC=contoso,DC=com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment