Strange behavior in Powershell
i came across strange behavior in powershell:
first ran these 2 commands. resulted in following:
can see typename set "selected.system.int32". became strange when discovered this:
now, typename set "pscustomobject". why different?
ps > $temp = 123 | select nr1, nr2 ps > $temp nr1 nr2 --- ---
first ran these 2 commands. resulted in following:
ps > $temp | gm typename: selected.system.int32 name membertype definition ---- ---------- ---------- equals method bool equals(system.object obj) gethashcode method int gethashcode() gettype method type gettype() tostring method string tostring() nr1 noteproperty nr1=null nr2 noteproperty nr2=null
can see typename set "selected.system.int32". became strange when discovered this:
ps > $temp.gettype() ispublic isserial name basetype -------- -------- ---- -------- true false pscustomobject system.object
now, typename set "pscustomobject". why different?
this correct select properties want powershell has create new custom object.
in powershell version 2 typename "selected.system.int32" given custom object make possible deduct custom object original object before select.
this name there you, basic type still pscustomobject
you can see how works looking @ psobject property, contains list of typenames
$temp.psobject.typenames
selected.system.int32
system.management.automation.pscustomobject
system.object
greetings mow
in powershell version 2 typename "selected.system.int32" given custom object make possible deduct custom object original object before select.
this name there you, basic type still pscustomobject
you can see how works looking @ psobject property, contains list of typenames
$temp.psobject.typenames
selected.system.int32
system.management.automation.pscustomobject
system.object
greetings mow
Windows Server > Windows PowerShell
Comments
Post a Comment