Welcome › Forums › General PowerShell Q&A › Get a data point from an associated data point
- This topic has 4 replies, 2 voices, and was last updated 3 months ago by
Participant.
-
AuthorPosts
-
-
October 16, 2020 at 7:25 pm #264023
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.
-
October 16, 2020 at 7:30 pm #264026
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;
-
October 17, 2020 at 4:59 am #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.
-
October 17, 2020 at 9:50 am #264137
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.
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. -
October 17, 2020 at 10:22 am #264149
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.
-
-
AuthorPosts
- The topic ‘Get a data point from an associated data point’ is closed to new replies.