Get a data point from an associated data point

Welcome Forums General PowerShell Q&A Get a data point from an associated data point

Viewing 4 reply threads
  • Author
    Posts
    • #264023
      Participant
      Topics: 1
      Replies: 3
      Points: 18
      Rank: Member

      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.

       

       

    • #264026
      Participant
      Topics: 1
      Replies: 3
      Points: 18
      Rank: Member

      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;

    • #264101
      Senior Moderator
      Topics: 9
      Replies: 1373
      Points: 5,061
      Helping Hand
      Rank: Community MVP

      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.

    • #264137
      Participant
      Topics: 1
      Replies: 3
      Points: 18
      Rank: Member

      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.

    • #264149
      Participant
      Topics: 1
      Replies: 3
      Points: 18
      Rank: Member

      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.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.