question

DaneBriggs-5625 avatar image
0 Votes"
DaneBriggs-5625 asked RichMatheisen-8856 commented

Powershell: Compare 2 columns with non-unique data

I have been tasked to write a script to import a CSV and determine if each user logs into a laptop, desktop or both. Some users log into multiple computers. I have a CSV of users and computers that they log into. How do I search through a column of the CSV that has duplicates and pull the data from another column and change the output? I feel like I am missing something simple

Example CSV
199331-image.png

Example of request output
199315-image.png




windows-server-powershell
image.png (7.9 KiB)
image.png (5.1 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you understand the answer to a very similar question you asked yesterday? powershell-searching-array-from-imported-csv-data.html

I'd use the same principal . . . create a hash and if the samaccountname exists as a key check the value. If it's the same, do nothing, if it differs replace it with "Both". When you've processed the whole data set, export the contents of the hash.

If you have a script you think should work but it doesn't, post your script. Also, instead of posting pictures of you sample data upload a file of those data. Nobody like doing data entry.



0 Votes 0 ·

I started to go down that path but ran into an issue.
There are duplicate values in samaccountname and Type. You can't have duplicate keys in a hash.

Since I can't use a hash I'm kind of at a loss as where to start

Sorry about the picture. Here is the raw data from the CSV

Input
samaccountname,Type
contoso\Jblow,Workstation
contoso\Jblow,Portable
contoso\jdoe,Workstation
contoso\Dsmith,Workstation
contoso\Dsmith,Workstation
contoso\BOFH,Portable



0 Votes 0 ·

But you CAN use a hash to do this!

Each samaccountname is a valid key. If it isn't in the hash, add it. Use the Workstation as the value. Get the next row.

OTOH, if the samaccountname is a key in the hash look at the value. If this row's Workstation is different to what's already in the hash, change the value to "both". Get the next row.

0 Votes 0 ·

0 Answers