Using content from only a single row of a CSV file

I’m working with a script for managing computers in our AD.
At the moment we have a script that contains info about each type of computer, the model name, default password and OU. But that means that each time we add a new type of computer we have to edit directly in the script. Which feels off.

Instead I’ve created a csv containing a row for each computer type containing the following columns: modelName ; model ; pwd ; ou

Basically I’d want to test if the first column in the csv (modelName) matches with $modelID which i get with:

$modelID = (Get-CimInstance -Class:Win32_ComputerSystem).Model

If so I would like to add the the three next columns (model, pwd, ou) in that row to variables of the same name ($model, $pwd, $ou), so I can basically run whichever function is needed with these values.

I’ve used “Import-Csv | ForEach-Object” before, but since I don’t really need to do something with each post but rather just do the comparison and then grab the contents of the rest of that row, I’m not really sure how best to go about this.

Easiest is still to use Import-CSV so that you get all the content in a variable.
Then search through that variable for the match.

E.g.

[pre]
$csvData = Import-CSV -Path <your csv path>

$modelID = (Get-CimInstance -Class:Win32_ComputerSystem).Model
$modelData = $csvData | Where-Object {$_.modelNAme -eq $modelID}

Now you can call the info with.

$modelData.modelName
$modelData.model
$modelData.pwd
$modelDate.ou
[/pre]

After the path in the first line you would add the path to your file.
It got lost since I used xml tag style around the text :slight_smile:

Thank you, that did the trick!

I was aware that I would need to use Import-Csv to get the content, but oftentimes that is paired with ForEach-Object to iterate over the entire CSV.