Pick at least 1 random name from each department and put them in a list

Welcome Forums General PowerShell Q&A Pick at least 1 random name from each department and put them in a list

Viewing 4 reply threads
  • Author
    Posts
    • #254210
      Participant
      Topics: 17
      Replies: 31
      Points: 133
      Rank: Participant

      Hey all,

      I have a CSV that has a list of departments and associated names, I am trying to pick at least one random name from each department and put the picked names and departments in another list.  I have done this with a do while loop but it is extremely slow, what is a more efficient way of doing it please?

      Thanks very much

       

    • #254237
      Senior Moderator
      Topics: 9
      Replies: 1408
      Points: 5,227
      Helping Hand
      Rank: Community MVP

      It would be nice if you can share us the code here, a different eye can point out the reason for the slowness 🙂

    • #254246
      Participant
      Topics: 17
      Replies: 31
      Points: 133
      Rank: Participant

      It would be nice if you can share us the code here, a different eye can point out the reason for the slowness 🙂

      Ahh I am sorry, here it is:

      • This reply was modified 2 months, 3 weeks ago by Swatto.
      • This reply was modified 2 months, 3 weeks ago by Swatto.
    • #254258
      Participant
      Topics: 16
      Replies: 1842
      Points: 3,514
      Helping Hand
      Rank: Community Hero

      Not sure how many records,but here is something to try:

      Output:

    • #254264
      Participant
      Topics: 17
      Replies: 31
      Points: 133
      Rank: Participant

      Thanks very much Rob – I will give that a go, it is around 4000 records, I take it I can Import-Csv | ConvertFrom-CSV to produce the key/value pairs?

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