Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Created November 7, 2018 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1RedOne/98d189ba324f36ac2d3c9e6925b78990 to your computer and use it in GitHub Desktop.
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
$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