Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Last active January 7, 2016 06:36
Show Gist options
  • Save midnightfreddie/e34c2e47824a08e5698d to your computer and use it in GitHub Desktop.
Save midnightfreddie/e34c2e47824a08e5698d to your computer and use it in GitHub Desktop.
$data = @{}
Import-Csv namecity.csv |
ForEach-Object {
if (-not $data[$_.name]) { $data[$_.name] = @{} }
$data[$_.name]["city"] = $_.city
}
Import-Csv namestate.csv |
ForEach-Object {
if (-not $data[$_.name]) { $data[$_.name] = @{} }
$data[$_.name]["state"] = $_.state
}
Import-Csv namecountry.csv |
ForEach-Object {
if (-not $data[$_.name]) { $data[$_.name] = @{} }
$data[$_.name]["country"] = $_.country
}
# Make use of this object format, or...
# Flatten data into tabular format
$data.Keys | ForEach-Object {
$Properties = [ordered]@{
name = $_
city = $data[$_].city
state = $data[$_].state
country = $data[$_].country
}
New-Object psobject -Property $Properties
} # Pipe here to Export-Csv, ConvertTo-Html or just emit objects or whatever
name city
Name1 City1
Name2 City2
name country
Name1 Country1
Name4 Country2
name state
Name1 State1
Name3 State2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment