Skip to content

Instantly share code, notes, and snippets.

@henno
Created December 22, 2016 18:23
Show Gist options
  • Save henno/9eb7a6f6a8b81d895edadd58ca44106f to your computer and use it in GitHub Desktop.
Save henno/9eb7a6f6a8b81d895edadd58ca44106f to your computer and use it in GitHub Desktop.
Load users to Active Directory from CSV
$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.
Firstname;Lastname;Maildomain;SAM;OU;Password
John;Smith;company.com;John.Smith;OU=My_AD_OU,DC=internal,DC=company,DC=com;Secr3t
@henno
Copy link
Author

henno commented Dec 22, 2016

> Set-ExecutionPolicy unrestricted
Execution Policy Change

> ./import_users.ps1
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment