• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1694
  • Last Modified:

Retrieving registry values with Get-ItemProperty

Regarding registry queries, I've often seen the advice that you need to specify the name of the property with get-itemproperty, and then use the property name again using the dot method to retrieve the value.  For example:
(Get-ItemProperty HKLM:\SOFTWARE\Intel\Infinst -name Infver).Infver

Open in new window


However, in my experience there's no need to supply the name twice.  The below works just fine.
(Get-ItemProperty HKLM:\SOFTWARE\Intel\Infinst).Infver

Open in new window


I was wondering if anyone knew some background on this and whether there are any circumstances where my method wouldn't work.  It's been tested with both PS 2.0 and 3.0, don't know about 1.0.  I can't understand why the previous advice prevails when it doesn't seem to be needed.
0
footech
Asked:
footech
  • 2
  • 2
2 Solutions
 
QlemoC++ DeveloperCommented:
Interesting question. It seems as if the -Name parameter of Get-ItemProperty acts as an property filter (as with Select-Object). This means for registry it is usually meaningless!

(gp $RegKey).$RegValue is indeed sufficient, and should not have big impact unless the registry key contains a lot of values. I don't know whether -Name is evaluated by the provider or PS, but I suppose the provider does the work, and so filtering can improve performance. That is the only potential con I can see for not using -Name.

That comes even more handy for reading more than one value for the same key:
$key = get-itemproperty $RegKey
write-Host $key.Value1
write-Host $key.Value2

Open in new window

0
 
footechAuthor Commented:
Interesting observation.  The syntax does seem to behave more like the -filter parameter on gci than the -include parameter (for instance, using wildcards).  If I ever run into a reg key with a large amount of values, I'll have to remember this and see if there's any measureable performance difference.
0
 
QlemoC++ DeveloperCommented:
If we could use get-itemproperty remotely, the potential impact would be noticable - if there is any.
0
 
SubsunCommented:
I agree with Qlemo.. With name parameter you can get value name and data of a specific registry entry which would be more quick and efficient when you work against a reg path with large number of values..

Another trivial difference/observation is (relevant only if you want to utilize the error details)
(Get-ItemProperty HKLM:\SOFTWARE\Intel\Infinst -name Infver).Infver
Will return "Property does not exist at path" error if the property doesn't exist
but  (Get-ItemProperty HKLM:\SOFTWARE\Intel\Infinst).Infver will not return any error..

I cannot think of any other relevant point here... :-)
0
 
footechAuthor Commented:
I appreciate the feedback guys!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now