Solved

Retrieving registry values with Get-ItemProperty

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

Author Closing Comment

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

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

749 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