Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Export to custom object with variable columns to CSV

$
0
0

I'm wrting a script collecting the accesscontrol of applications, the items in accesscontrol can vary from one to many.
(This data is originating from a xml file).

The problem I'm facing is that one of the columns of the resulting Array ($Temp) is missing (AccessControl3), in the GridView.
When I change the order of the addition of the Items to the resulting Array, the column (AccessControl3) is pressent.
When examining $Temp, in both situations, it contains all the columns of the items added.
The problem apears when converiting the resulting Array to a CSV or grid.

The order of the Items added to the resulting Array is completely random, as well the amount of AccessControl columns.

The script below is an example of the described problem.

What i'm missing?


-- script -------------------------------------------------------------------------------------------

$Temp=@()

$Item1 = New-Object PSObject
$Item1 | Add-Member -membertype Noteproperty -Name Name -Value "App1"
$Item1 | Add-Member -membertype Noteproperty -Name AccessControl1 -Value "Group1"
$Item1 | Add-Member -membertype Noteproperty -Name AccessControl2 -Value "Group2"

$Item2 = New-Object PSObject
$Item2 | Add-Member -membertype Noteproperty -Name Name -Value "App2"
$Item2 | Add-Member -membertype Noteproperty -Name AccessControl1 -Value "Group1"
$Item2 | Add-Member -membertype Noteproperty -Name AccessControl2 -Value "Group2"
$Item2 | Add-Member -membertype Noteproperty -Name AccessControl3 -Value "Group3"

$Temp += $Item1
$Temp += $Item2

#$Temp += $Item2
#$Temp += $Item1


$Temp | Out-GridView

-- script -------------------------------------------------------------------------------------------


Viewing all articles
Browse latest Browse all 6937

Trending Articles