Last active
August 16, 2016 04:35
-
-
Save Dan1el42/6021baecb976aeb588310e4fb4b9a401 to your computer and use it in GitHub Desktop.
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
# Sample data | |
$systemData = @{ | |
'System1' = @( | |
'Person1' | |
'Person2' | |
'Person3' | |
) | |
'System2' = @( | |
'Person1' | |
'Person3' | |
) | |
'System3' = @( | |
'Person5' | |
) | |
'System4' = @( | |
'Person2' | |
'Person3' | |
'Person4' | |
'Person5' | |
) | |
} | |
# Determine highest number of users across all systems | |
$maxSystemUsers = 0 | |
foreach ($array in $systemData) { | |
if ($array.Count -gt $maxSystemUsers) { | |
$maxSystemUsers = $array.Count | |
} | |
} | |
# Get a sorted array of all system names | |
$systemNames = $systemData.Keys | Sort-Object | |
# Enumerate system users | |
$systemResults = for ($i = 0; $i -lt $maxSystemUsers ; $i++) { | |
$tempRowDict = New-Object -TypeName System.Collections.Specialized.OrderedDictionary | |
foreach ($systemName in $systemNames) { | |
$value = $systemData[$systemName] | |
if ($i -lt $value.Count) { | |
$tempRowDict[$systemName] = $value[$i] | |
} | |
} | |
New-Object -TypeName PSObject -Property $tempRowDict | |
} | |
# Output | |
$systemResults #| ConvertTo-Csv -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment