79739171

Date: 2025-08-18 19:42:58
Score: 1
Natty:
Report link

The following code worked for me (Thank you, @Mathias R. Jessen !)

$content1 = Import-Csv -Path "C:\Users\blah\Desktop\Test\test1.csv"
$content2 =  Import-Csv -Path "C:\Users\blah\Desktop\Test\test2.csv"

# create hash table to be used as a mapping table
$nameToIDsMap = @{}

# add each row from the csv to the mapping table - use realName as key, userName as value
$content1 | ForEach-Object {
  $nameToIDsMap[$_.realName] += @($_.userName)
}

$content2 | ForEach-Object {
  $personRecord = $_
  $nameToIDsMap[$personRecord.Name] |ForEach-Object {
    [pscustomobject]@{
      UserName = $_
      RealName = $personRecord.Name
      Roles = $personRecord.ApprovedGroups
    }
  }
} | Export-Csv "C:\Users\blah\Desktop\Test\test3.csv" -NoTypeInformation
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Whitelisted phrase (-1): worked for me
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Mathias
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: CyberUn1c0rn