Solved

Retrieving registry values with Get-ItemProperty

Posted on 2013-05-19
5
1,543 Views
Last Modified: 2013-05-20
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
Comment
Question by:footech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 350 total points
ID: 39179689
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
 
LVL 40

Author Comment

by:footech
ID: 39181797
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 39181888
If we could use get-itemproperty remotely, the potential impact would be noticable - if there is any.
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 150 total points
ID: 39182260
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
 
LVL 40

Author Closing Comment

by:footech
ID: 39182393
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question