Question: I have an entire script for creating bulk users in Active Directory. However, I didn't include any managers and now need to add them to
I have an entire script for creating bulk users in Active Directory. However, I didn't include any managers and now need to add them to the CSV file I am using. How can I edit my PowerShell script so that the managers will import to Active Directory as well as the new users I am trying to create? Below is my script:
# 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
#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 } }

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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
