Created
December 22, 2016 18:23
-
-
Save henno/9eb7a6f6a8b81d895edadd58ca44106f to your computer and use it in GitHub Desktop.
Load users to Active Directory from CSV
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
$Users = Import-Csv -Delimiter ";" -Path "C:\Users\Administrator\Desktop\users.csv" | |
foreach ($User in $Users) | |
{ | |
$Displayname = $User.'Firstname' + " " + $User.'Lastname' | |
$UserFirstname = $User.'Firstname' | |
$UserLastname = $User.'Lastname' | |
$OU = $User.'OU' | |
$SAM = $User.'SAM' | |
$UPN = $User.'Firstname' + "." + $User.'Lastname' + "@" + $User.'Maildomain' | |
$Password = $User.'Password' | |
New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName $SAM -UserPrincipalName $UPN -GivenName "$UserFirstname" -Surname "$UserLastname" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $false -PasswordNeverExpires $true -server pp1.sise.puhastusproff.ee | |
} |
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4. in line 1.
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
Firstname;Lastname;Maildomain;SAM;OU;Password | |
John;Smith;company.com;John.Smith;OU=My_AD_OU,DC=internal,DC=company,DC=com;Secr3t |
Author
henno
commented
Dec 22, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment