Sorry if this has been asked elsewhere but I can't find the answer! I have written a Powershell script to update AD account information (things like Office, Department, Job Title etc.) with data pulled from a CSV file exported from our HR database. The CSV file has column headings like this:
"Personal Reference:People","Forename1:People","Surname:People","Cost Centre ID","Reporting Unit","Post","E-slip Email Address:People","Preferred Name:People","Full Name:Manager","Level3:Structure","Personal Ref:Manager"
The script looks up the line in the CSV file containing the employee ID number of the account I want to update and it reads that line into an array like this:
$csvLine = (Select-String -Path $EmployeeData -Pattern $UserToUpdate.EmployeeID) -split ","
Where $EmployeeData is the CSV file and $UserToUpdate is the AD account I want to update, selected earlier in the script usingGet-ADUser. I then select the items I want from the $csvLinearray and use those details to update the AD account.
This all works fine for most employees but managers will have their employee ID listed multiple times in the file. It will be in the"Personal Reference:People" column once but will also appear in the"Personal Ref:Manager" column for every member of staff they manage. What I need to do is make sure that I only select the line in which the employee ID appears in the "Personal Reference:People"column. Is there a way of doing that using Select-String or do I need to use another method of getting the line I want?
Thanks,
Liam