Strange behavior in Powershell


i came across strange behavior in powershell:

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


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file