Skip to content

Instantly share code, notes, and snippets.

@NateWeiler
Last active June 16, 2020 05:15
Show Gist options
  • Save NateWeiler/a61ee57800b766b5d7eea14fedaefe30 to your computer and use it in GitHub Desktop.
Save NateWeiler/a61ee57800b766b5d7eea14fedaefe30 to your computer and use it in GitHub Desktop.
add bulk users using powershell and simple csv
#import the AD module
Import-Module activedirectory
#Tu will import from csv
$ ADUsers = Import-csv C: \ Users \ Administrator \ Desktop \ users.csv
#i we loop for every user
foreach ($ User in $ ADUsers)
{
$ Username = $ User.username
$ Password = $ User.password
$ Firstname = $ User.firstname
$ Lastname = $ User.lastname
$ OU = $ User.ou
# to see if a user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $ Username})
{
#If user does exist, give a warning
Write-Warning "Account with username $ Username already exists in AD"
}
else
{
New-ADUser `
-SamAccountName $ Username `
-UserPrincipalName "[email protected]" `#here you edit the domain
-Name "$ Firstname $ Lastname" `
-GivenName $ Firstname `
-Surname $ Lastname `
-Enabled $ True `
-DisplayName "$ Lastname, $ Firstname" `
-Path $ OU `
-AccountPassword (convertto-securestring $ Password -AsPlainText -Force) -ChangePasswordAtLogon $ True # I decided that changing the password at login will be the best option
}
}
#Mr. Richard Stallman, bless my code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment