Solved

Retrieving registry values with Get-ItemProperty

Posted on 2013-05-19
5
1,401 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 69

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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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