What I try to do is quite simple: create a custom object with some properties, and then define "groups" of properties (columns) for use in Select-Object. Let me clarify:
$props = @{"Mary"=1;"Jane"=2;"Frank"=3;"John"=5;"Brenda"=6}
$obj = New-Object PSObject $props
I now have a custom object with some bogus data. What I now want to be able to do is
$obj | select Male
$obj | select Female
And what I had thought would do the trick, is something like this:
$obj | Add-Member PropertySet "Male" @("Frank","John")
$obj | Add-Member PropertySet "Female" @("Mary","Jane","Brenda")
It doesn't work - I get this error:
Add-Member : Cannot convert the "System.Object[]" value of type
"System.Object[]" to type "System.Collections.ObjectModel.Collection`1[System.String]".
I guess I should provide another object type than my array to Add-Member
, but I'm unsure how I should do that.
Does anyone have experience with this?
Important note: I'm on Powershell 2, and I read on various sites that it has a bug that doesn't allow setting the default properties. That's not what I want to do - I want to create a custom property set and not a default one - but it could be that this bug also prevents me from getting what I want.