I’m trying make a script to import users from a .csv into AD using Powershell. I’ve made the fields I wanted imported into an excel document.

Set First Name for users.

Set Last Name for users.

Set Display Name.

Set User Name.

Assign Users to their Groups.

Enable the User.

Set the default password.

I’ve found many different scripts that gives more information than I need and I’ve tried just parsing out the things I don’t need but I wind up just making them unusable. I’ve not touched Powershell in 2 years and even then my skills were rudimentary at best. Thank you in advance for any advice.

5 Spice ups

Maybe this will have what you need:

Does it matter in my script if they are in order of the .csv?

Your script will need to assign things correctly, but the order in the CSV doesn’t matter.

I’ve also found this resource in my searches.

I’m still trying to get mine to work.

It’ll help if you post the script you’re using.

Post your attempt to solve it. This community will surely solve the problem you are facing.

Import active directory module for running AD cmdlets

Import-Module activedirectory

#Store the data from ADUsers.csv in the $ADUsers variable

$ADUsers = Import-csv .\ADUsers.csv

#Loop through each row containing user details in the CSV file

foreach ($User in $ADUsers)

{

#Read user data from each field in each row and assign the data to a variable as below

$Username = $User.username

$Password = $User.password

$Firstname = $User.firstname

$Lastname = $User.lastname

$OU = $User.ou #This field refers to the OU the user account is to be created in

#Check to see if the user already exists in AD

if (Get-ADUser -F {SamAccountName -eq $Username})

{

#If user does exist, give a warning

Write-Warning “A user account with username $Username already exist in Active Directory.”

}

else

{

#User does not exist then proceed to create the new user account

#Account will be created in the OU provided by the $OU variable read from the CSV file

New-ADUser `

-SamAccountName $Username `

-UserPrincipalName “$Username@emeneye.ac.uk” `

-Name “$Firstname $Lastname” `

-GivenName $Firstname `

-Surname $Lastname `

-Enabled $True `

-DisplayName “$Lastname, $Firstname” `

-Path $OU `

-AccountPassword (convertto-securestring $Password -AsPlainText -Force)

}

}