Solved

Retrieving registry values with Get-ItemProperty

Posted on 2013-05-19
5
1,351 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
  • 2
  • 2
5 Comments
 
LVL 68

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 39

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 68

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 39

Author Closing Comment

by:footech
ID: 39182393
I appreciate the feedback guys!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now