Get a data point from an associated data point

Dilemma: I have a CSV file with two columns. Column 1 is User and column 2 is Computer. I need to write a script that asks for the username in column 1 and then grab the associated computer name in column 2 and then use the computer name as a variable to add/delete printers. I have tried for 2 days with zero results. I admit that a year in, my PS skills are not that great. Any help from you fine folks would be greatly appreciated. I’ve tried Out-String and many other tactics with zero joy.

 

 

As an example of what I’ve done so far…

$path = $env:USERPROFILE + “\Desktop\names.csv”

$user = Read-Host “Enter username”

$computer = Import-Csv $path | where User -eq $user | Select-Object -ExpandProperty Computer | Out-String;

What are the headers for the csv ? the code should work if the headers are User and Computer and you don’t need to use Out-String as -ExpandProperty will do it.

[quote quote=264101]What are the headers for the csv ? the code should work if the headers are User and Computer and you don’t need to use Out-String as -ExpandProperty will do it.

[/quote]

Thank you for your answer.
They are User and Computer. What I want to do is using the User name, which I prompt for, associate that with the user’s computer name and grab the computer name for use in a variable ($computer) that can used to add/delete printers. I’m lost at this point.

OK, I see that using just -ExpandProperty works and outputs the computer name to stdout. How do I feature this as a variable? Do I just declare it in the next action(s)? PS is still elusive to me.

Thank you.