I've got this hashtable of users called $userTable
which is of the form:.
<key = string, value = PSObject>
Objects are added to the hashtable as follows:
$userTable = @{}
$id="1056456"
$user = New-Object PSObject -Property @{
Name="Test Name"
Email="Test Email"
Systems = New-Object System.Collections.ArrayList
}
$system1 = New-Object PSObject -Property @{
Name="System 1"
Admin=$true
Status="Active"
}
$system2 = New-Object PSObject -Property @{
Name="System 2"
Admin=$false
Status="Inactive"
}
$user.Systems.Add($system1) | Out-Null
$user.Systems.Add($system2) | Out-Null
$userTable.Add($id, $user)
So for each entry in $userTable
, there is a name, an email and a list of systems associated with that user.
What I want to do is export this data to .csv
such that it takes the following form:
ID, Name, Email, System Count, System1 Name, System1 Admin, System1 Status, System2 Name, etc..
There may be more than 2 systems per user.
I cannot get my head around how to export this to a .csv file.
Any help would be appreciated, thanks.
I was thinking of using something along the lines of:
$userTable.GetEnumerator() |
Select-Object -Property @{N='ID'; E={$_.Key}},
@{N='Name'; E={$_.Value.Name}},
@{N='Email'; E={$_.Value.Email}},
@{N='System Count'; E={$_.Value.Systems.Count}} |
Export-Csv -NoTypeInformation -Path C:\Documents\test.csv
But that does not include the System Array List (yet)