Question
I am trying to create a script to bulk add users in a test Active Directory environment. Everything loads correctly except the Manager column. This
I am trying to create a script to bulk add users in a test Active Directory environment. Everything loads correctly except the Manager column. This won't load into the organization section of a user's profile at all. Here is my script and CSV I'm using.
# Import active directory module for running AD cmdlets Import-Module activedirectory #Store the data from ADUsers.csv in the $ADUsers variable $ADUsers = Import-csv 'C:UsersAdminDesktopSuccessful ScriptSample AD CSV for Import.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 $FirstName = $User.FirstName $LastName = $User.LastName $DisplayName = $User.DisplayName $Lastname = $User.Lastname $OU = $User.OU #This field refers to the OU the user account is to be created in $EmailAddress = $User.EmailAddress $Username = $User.Username $Password = $User.Password $JobTitle = $User.JobTitle $Department = $User.Department $Company = $User.Company $Description = $User.Description $Telephone = $User.Telephone $Manager = $User.Manager
#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@ADTest.com" ` -Name "$FirstName $LastName" ` -GivenName $FirstName ` -Surname $LastName ` -Enabled $True ` -DisplayName "$LastName, $FirstName" ` -Path $OU ` -Description $Description ` -Company $Company ` -EmailAddress $EmailAddress ` -Title $JobTitle ` -OfficePhone $Telephone ` -Department $Department ` -AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True } }
I can send the actual CSV file if needed.
Department Company Description Telephone Manager CEO OU Username Password ThKern AD Tes EMP ID 60133 912-250 343 AD Test Board OU-Users,OU-r AD Test EMP ID 33269 205-794-966 Kern, Thomas OU-Users,OU AD Test EMPID 82272 203-342-375 Kern, Thomas OU-Users,OUr JobTitle FirstName LastName DisplayName Thomas Kern EailAddress -User,oua ThKe60133 CEO Chief Executive Office officer SEc elma Jack Jackson, VelmaVelackson@ADTest.comVelackson Vela33269 CIO Chief Information Officer ITS Peggy McKenzie McKenzie, Peggy PeMcKenzie@ADTest.comPeMckenzie PeMc82272 CSO Chief Security Officer Kern, Thomas ThKern@ADTest.com Department Company Description Telephone Manager CEO OU Username Password ThKern AD Tes EMP ID 60133 912-250 343 AD Test Board OU-Users,OU-r AD Test EMP ID 33269 205-794-966 Kern, Thomas OU-Users,OU AD Test EMPID 82272 203-342-375 Kern, Thomas OU-Users,OUr JobTitle FirstName LastName DisplayName Thomas Kern EailAddress -User,oua ThKe60133 CEO Chief Executive Office officer SEc elma Jack Jackson, VelmaVelackson@ADTest.comVelackson Vela33269 CIO Chief Information Officer ITS Peggy McKenzie McKenzie, Peggy PeMcKenzie@ADTest.comPeMckenzie PeMc82272 CSO Chief Security Officer Kern, Thomas ThKern@ADTest.comStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started