While going through Don Jones’ “Ditch Excel” I have been testing some code and don’t understand why I am seeing the results I am getting. I am trying to change the TypeName from …PSCustomObject to Reports.ObjExam. When I run $objectCollection.pstypenames I see my expected result but when I pipe the variable to GM I still see the PSCusomObject.
In a separate script I have created a new object and used Insert() to assign a new TypeName, but in my code below I can’t seem to make it work.
What did I do wrong?
$groups = 'Group101', 'Group102'
$users = 'User1', 'User2'
$properties = @{User=''; Group=''; Dummy = 'Default'}
$objectTemplate = New-Object -typename PSObject -Property $properties
$objectCollection=$groups | ForEach-Object{
$groupCurrent = $_
$users | ForEach-Object{
$usersCurrent = $_
$objectCurrent = $objectTemplate.PSObject.Copy()
$objectCurrent.group = $groupCurrent
$objectCurrent.user= $usersCurrent
$objectCurrent
}
}
$objectCollection | ft -autosize
$objectCollection.pstypenames.Insert(0,'Reports.ObjExam')
$objectCollection.pstypenames
$objectCollection | GM