Created
November 7, 2018 19:51
-
-
Save 1RedOne/98d189ba324f36ac2d3c9e6925b78990 to your computer and use it in GitHub Desktop.
Search for matching records in a big csv using the .Where Method for speed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$csv = ConvertFrom-CSV "ComputerName,KBNeeded | |
Server01,KB1234567 | |
Server02,KB1234567 | |
Server03,KB1234567 | |
Server04,KB1234567 | |
Server05,KB1234567 | |
Server01,KB3456789 | |
Server01,KB5678910" | |
$uniquePCs = $csv | Group-Object -Property ComputerName | Select -ExpandProperty Name | |
ForEach ($uniquePC in $uniquePCs){ | |
[pscustomobject]@{ComputerName=$uniquePC;Patch=$csv.Where({$_.ComputerName -eq $uniquePC}).KBNeeded -join ","} | |
} | |
<# | |
ComputerName Patch | |
------------ ----- | |
Server01 KB1234567,KB3456789,KB5678910 | |
Server02 KB1234567 | |
Server03 KB1234567 | |
Server04 KB1234567 | |
Server05 KB1234567 | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment