Ok, maybe I'm thinking too much like a C# programmer, but here's my issue. I have a need to create a high level custom object, add some members, and then in a lower for loop create some custom objects, add them to an array, then add that array as a member of the high level custom object. So, I'm going to try and give a visual here.
$arrObjectCollection = @()
foreach ($strSomething in $arrSomething)
{
$objHighLevel = New-Object PSObject
Add-Member -InputObject $objHighLevel -MemberType NoteProperty -Name "Something" -Value "Some Value"
$arrLowLevelCollection = @()
foreach ($strSomethingElse in $arrSomethingElse)
{
$objLowLevel = New-Object PSObject
Add-Member -InputObject $objLowLevel -MemberType NoteProperty -Name "SomethingLow" -Value "Something"
##Some Code
## More Add-Member Calls
$arrLowLevelCollection += $objLowLevel
}
Add-Member -InputObject $objHighLevel -MemberType Property -Name "Low Level Results" -Value $arrLowLevelCollection
$arrObjectCollection += $objHighLevel
}
$arrObjectCollection | Export Clixml -Path "C:\Temp\Test.xml"
So imagine that the $objHighLevel represents a Windows host, and so there may be many hosts we are reporting on, so many $objHighLevel objects in the $arrObjectCollection array. Now the "Low Level Results" could represent the drives, with one $objLowLevel being a drive with the members of $objLowLevel representing various data about the drive, so the $arrLowLevelCollection array would be an array of all the drive objects, which then need to get added to the $objHighLevel object because the drives belong to that host. As we all know, there could be one or many drives, so this is the best solution my brain can come up with.
After all that, one may wonder what I'm asking... Well, trying what I have above, when I try to perform the Add-Member function to add the $arrLowLevelCollection to the $objHighLevel I get all kinds of errors and I just cannot figure this out.