Skip to content

Instantly share code, notes, and snippets.

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 Dan1el42/6021baecb976aeb588310e4fb4b9a401 to your computer and use it in GitHub Desktop.
Save Dan1el42/6021baecb976aeb588310e4fb4b9a401 to your computer and use it in GitHub Desktop.
# 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