MUY Belgium
MUY Belgium

Reputation: 2452

Indirect reference to a object member is powershell

I have an object :

Get-ItemProperty -Path ("Registry:"+$my_registry_key) -Name $my_entry

But I still have several useless properties. I would like to compare wath is expected to get out (a string) to zero.

Since % operator is maybe a bit too magical... I would like to expend it to make an indirect reference to property instead of a direct (or hard-coded one). What does happens if property does not exists?

( `
 ( Get-ItemProperty -Path ("Registry:$my_registry_key") `
 | need_some_magic -property $my_entry`
 ) -ne 0 `
)

And expect one boolean (either $false or $true).

Does Powershell have some kind of hash which can be retrieved through variable instead of $_.property.

Upvotes: 0

Views: 370

Answers (1)

arco444
arco444

Reputation: 22861

You can do the following:

Get-ItemProperty -Path ("Registry:"+$my_registry_key) | select -ExpandProperty $my_entry

So:

if($(Get-ItemProperty -Path ("Registry:"+$my_registry_key) | select -ExpandProperty $my_entry) -ne 0) {
  ...
}

Upvotes: 2

Related Questions