Hi there!
I created the following pscustomobject with a nested pscustomobject. Interestingly after Select-Object -Expandproperty the source object is changed. Do you have an answer on that?
# Create array for subobject object
$subobject = @()
$subobject += [pscustomobject]@{'FieldName'='Value1';'FieldNameX'='Value2'}
$subobject += [pscustomobject]@{'FieldName'='Value3';'FieldNameX'='Value4'}
# Create hashtable
$arr = @{}
$arr.Object1 = $subobject
$arr.NameX = 'ValueX'
Write-Host 'source array:'
$arr
# create pscustomobject
$myobject = [pscustomobject]$arr
Write-Host 'myobject before output with select-object -expandproperty:'
$myobject
Write-Host 'myobject output with select-object -expandproperty:'
$myobject | Select-Object * -ExpandProperty Object1
Write-Host 'myobject after output with select-object -expandproperty:'
$myobject
--- After running the script $myobject is changed:
NameX : ValueX
Object1 : {@{FieldName=Value1; FieldNameX=Value2; NameX=ValueX; Object1=System.Object[]}, @{FieldName=Value3; FieldNameX=Value4; NameX=ValueX; Object1=System.Object[]}}
--- Expected content of myobject:
NameX : ValueX
Object1 : {@{FieldName=Value1; FieldNameX=Value2}, @{FieldName=Value3; FieldNameX=Value4}}
Thank you!
Have a great day!
-Bruno.