ADUC Powershell Automation

Import-Module ActiveDirectory
$users =Import- Csv file path

ForEach ($user in $users) {
$GivenName = $user.‘First Name’
$Surname = $user.‘Last Name’
$Title = $user.‘Job Title’
$OfficePhone = $user.‘Office Phone’
$EmailAddress = $user.‘Email Address’
$Description = $user.Description
$Path = $user.‘Organizational Unit’
$Enabled = ([System.Convert]::ToBoolean($user.Enabled))
}

It accepts it as script but then it doesnt populate the users, what is wrong.

Thank you!

Hi @cameron3703

Check the import file path. Try with:

# Import required  modules
Import-Module ActiveDirectory

# Prompt user for CSV file path
$filepath = "C:\ps1\newusers1.csv"

# Import File to variable
$users = Import-Csv $filepath

Ricardo

Its still not working. I tried typing out the file and prompting the user for the file

# Import the AD Module
Import-Module ActiveDirectory

# Get the path to our target CSV file
$filepath = Read-Host -Prompt "Please enter the path to the CSV file that contains the new user accounts"

# Import the CSV as an array
$users = Import-CSV $filepath

# Complete an action for each user in the CSV file
ForEach ($user in $users) {
    # Do this for each user
    New-ADUser `
        -Name ($user.'First Name' + " " + $user.'Last Name') `
        -GivenName $user.'First Name' `
        -Surname $user.'Last Name' `
        -UserPrincipalName ($user.'First Name' + "." + $user.'Last Name') `
        -AccountPassword (ConvertTo-SecureString "P@$$w0rd123" -AsPlainText -Force) `
        -Description $user.Description `
        -EmailAddress $user.'Email Address' `
        -Title $user.'Job Title' `
        -OfficePhone $user.'Office Phone' `
        -Path $user.'Organizational Unit' `
        -ChangePasswordAtLogon 1 `
        -Enabled ([System.Convert]::ToBoolean($user.Enabled))
}

try this one

I tried that it didn’t work

If you are doing this in the lab you will need to do 2 things to make your life easier.
1# rename the csv file so it is easier to add to prompt
2# edit csv file and put in correct organizational unit paths. the csv was written for a different domain.
go to active directory users and computers under tools and then turn on advance features in the view menu find the server academy ou from the domain drop down and right click and properties select attributes tab and find distinguished name click that and copy that.

you will need to paste it in the right spots in the csv file then save it. This should let the script work properly now.

I checked the lab but did not get the same message as in your lab. What you did do to get that message? just clicked the button?

Also, In case the users don’t show up check the OU under ServerAcademy it might be placed in the wrong OU or need an AD refresh to see them.

Ricardo

If I use -Surname it gives me a bunch of errors. I updated the Organizational Units. I used the first script I showed you. Its asking me to enter the values otherwise I get no other errors. Can I get a lesson request.

Nevermind I got it. You have to type out Name, GivenName, Surname, UserPrincipalName, AccountPassword, Description, EmailAddress, Title, OfficePhone, Path, Enabled

you cant leave any out like I was doing. Problem solved

Thank you, you helped me solve the problem.