![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Select object with escaped wildcard Hello there, I'm confused about how things work in this example: New-Object psobject| Add-Member noteproperty '*' 'a' -pass | select - expand '`*' I think it should work, but it doesn't. Even adding backticks doesn't effect the result - it still returns error '''Select-Object : Property "`*" cannot be found.''' (the reason why I try to solve it because I have some PSObject-s with automatically added properties and the property names are not restricted) Does anybody have the idea how to get the property (with a special wildcard character in its name) using select-object? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Select object with escaped wildcard Hi, well, in this case you can always refer to psobject.Properties: $(New-Object psobject| Add-Member noteproperty '*' 'a' - pass).psobject.Properties | Where {$_.Name -eq "*"} I understand what you are trying to reach and I agree that escape character should work in this case. Martin |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Select object with escaped wildcard Thanks for reply, Martin. I prefer shorter way: (New-Object psobject| Add-Member noteproperty '*' 'yes' -pass)."*" but you reminded me in your answer, that there is something I don't use very ofteh - that there is psobject property with some interesting methods. (I was tempted to submit it as a bug, but was not sure if I was right. I'll wait some time before the submit. ) On 3 lis, 09:35, Martin Zugec <martin.zu...@newsgroup> wrote: Quote: > Hi, > > well, in this case you can always refer to psobject.Properties: > > $(New-Object psobject| Add-Member noteproperty '*' 'a' - > pass).psobject.Properties | Where {$_.Name -eq "*"} > > I understand what you are trying to reach and I agree that escape > character should work in this case. > > Martin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Select object with escaped wildcard Both psobject and psbase are extremely important if you want to dig deeper into Powershell and use it to script something it was never designed for. Whenever I found myself in situation that I try to do something that Posh doesn't expect or when I run into situation that Posh tries to be too smart, I am refering to psobject or psbase. For me, most typical and painful usage is while handling with XML documents\elements. While in Posh v2 (my dev station), most properties are directly supported, if you try to run same code in Posh v1, it will fail (for example ParentNode, InnerText etc etc). I remember that I encountered similar situation as yours at one customer - quick solution was to develop wrapper around Select that was called Get-Property and was using psobject (there were few other reasons for this). Martin |
My System Specs![]() |
| | #5 (permalink) |
| | RE: Select object with escaped wildcard In PowerShell v1, Select-Object -ExpandProperty only works on values that are arrays: So in v1 this would work, becuase the property '*' contains an array as the value: $array = "a","b" $x = New-Object psobject | add-member noteproperty '*' $array -PassThru $x | select -ExpandProperty '*' In v2 the value does not have to be an array, so you can simply do this: $x = New-Object psobject | add-member noteproperty '*' 'a' -PassThru $x | select -ExpandProperty '*' To solve your issue using v1 you can use foreach-object: $x = New-Object psobject | add-member noteproperty '*' 'a' -PassThru $x | ForEach-Object {$_.'*'} "stej" wrote: Quote: > Hello there, I'm confused about how things work in this example: > > New-Object psobject| Add-Member noteproperty '*' 'a' -pass | select - > expand '`*' > > I think it should work, but it doesn't. Even adding backticks doesn't > effect the result - it still returns error '''Select-Object : Property > "`*" cannot be found.''' > > (the reason why I try to solve it because I have some PSObject-s with > automatically added properties and the property names are not > restricted) > > Does anybody have the idea how to get the property (with a special > wildcard character in its name) using select-object? > . > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| select-object bug? | PowerShell | |||
| Unable to Select-Object | PowerShell | |||
| Select-Object in PS1 Script Bug?! | PowerShell | |||
| Select Multi Object in (my) computer | Vista General | |||
| Select object as | PowerShell | |||