Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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