{"id":9461,"date":"2012-05-11T00:01:00","date_gmt":"2012-05-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/05\/11\/use-powershell-to-enumerate-registry-property-values\/"},"modified":"2012-05-11T00:01:00","modified_gmt":"2012-05-11T00:01:00","slug":"use-powershell-to-enumerate-registry-property-values","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-enumerate-registry-property-values\/","title":{"rendered":"Use PowerShell to Enumerate Registry Property Values"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to enumerate all the properties and their values under a registry key.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! I have a question. It seems that getting the property values under a registry key is a tedious process. It looks like I need to know the exact property value to find out its value. Often I do not have this information. I would like a way to say, &ldquo;Just give me the property values and their associated value.&rdquo; I do not want to do a lot of work to get this information. Is it possible?<\/p>\n<p>&mdash;BW<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello BW,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. I just checked on the status of an order of Monkey Picked Oolong Tea that the Scripting Wife ordered for me. It arrives tomorrow. Charlotte, North Carolina in the United States is not a huge tea market&mdash;but hey, I have great Internet access at home and that gives me access to some of the best tea brokers in the world. I first ran across Monkey Picked tea in a small tearoom while the Scripting Wife and I were on our way to the <a href=\"http:\/\/minasiconference.wordpress.com\/\" target=\"_blank\">Mark Minasi Conference<\/a>. I had the Monkey Picked Oolong; she had hot chocolate. But she remembered how much I kept going on and on about the light and delicate flavor, and next thing I know, we have a package arriving tomorrow.<\/p>\n<p style=\"padding-left: 30px\"><b>Note<\/b>&nbsp;&nbsp;&nbsp;This is the fifth blog in a series of Hey, Scripting Guy! Blogs that discuss using the Registry provider. The first blog, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/05\/07\/use-the-powershell-registry-provider-to-simplify-registry-access.aspx\" target=\"_blank\">Using the Registry Provider to Simply Registry Access<\/a><i> <\/i>posted on Monday. Tuesday I discussed <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/05\/08\/use-powershell-to-back-up-system-state-prior-to-making-changes.aspx\" target=\"_blank\">using the *restore* cmdlets<\/a> to perform a system state backup of a computer prior to manipulating the registry. On Wednesday I talked about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/05\/09\/use-powershell-to-easily-create-new-registry-keys.aspx\" target=\"_blank\">creating new registry keys and assigning default values<\/a>. In the fourth blog, I talked about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/05\/10\/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx\" target=\"_blank\">creating new registry keys on remote computer systems<\/a>. I also discussed creating registry property values. For additional information about working with the registry via Windows PowerShell, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/operating+system+\/registry\/\" target=\"_blank\">see this collection of blogs<\/a>.<\/p>\n<h2>Working with registry property values<\/h2>\n<p style=\"padding-left: 30px\"><b>Note<\/b>&nbsp;&nbsp;&nbsp; For a VBScript version of this blog, see <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2008\/04\/08\/how-can-i-retrieve-all-the-values-in-a-registry-key.aspx\" target=\"_blank\">Hey, Scripting Guy! How Can I Retrieve All the Values in a Registry Key?<\/a><\/p>\n<p>Because of the hierarchical nature of the registry in Windows, the file system metaphor sort of breaks down. On a file system drive, you can use the <b>New-Item<\/b> cmdlet to create a folder (directory), and then go back and create a file inside the folder by using the same cmdlet. With the registry, that is not the case. <b>New-Item<\/b> creates the registry keys, but it is the <b>New-ItemProperty<\/b> cmdlet that creates the properties that are associated with the registry keys. This concept is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6305.hsg-5-11-12-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6305.hsg-5-11-12-01.png\" alt=\"Image of Registry Editor\" title=\"Image of Registry Editor\" \/><\/a><\/p>\n<p>Yesterday&rsquo;s Hey, Scripting Guy! Blog talked about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/05\/10\/use-powershell-to-create-new-registry-keys-on-remote-systems.aspx\" target=\"_blank\">retrieving registry properties<\/a>. In that blog, I discussed using the <b>Get-ItemProperty<\/b> cmdlet to retrieve registry property values, in addition to the specific registry property value value. (I know, it gets a little redundant). But as you pointed out, BW, from the perspective of perusing preset registry values, knowing an exact registry property value name is not the most efficient way of doing things.<\/p>\n<h2>Enumerating registry property values<\/h2>\n<p>The image that follows illustrates the <i>Winlogon <\/i>registry key. This registry key has four registry properties (in addition to the <i>Default<\/i> registry property, which is not set in this example).<i> <\/i><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5756.hsg-5-11-12-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5756.hsg-5-11-12-02.png\" alt=\"Image of Registry Editor\" title=\"Image of Registry Editor\" \/><\/a><\/p>\n<p>There are several steps involved in obtaining the value of the registry property values under a specific registry key.<\/p>\n<p>Only the steps&hellip;<\/p>\n<p>Enumerating registry property values:<\/p>\n<ol>\n<li>Use the <b>Push-Location<\/b> cmdlet to store the current working location.<\/li>\n<li>Use the <b>Set-Location<\/b> cmdlet to change the current working location to the appropriate registry drive.<\/li>\n<li>Use the <b>Get-Item<\/b> cmdlet to retrieve the properties of the registry key.<\/li>\n<li>Pipe the registry properties through the <b>ForEach-Object<\/b> cmdlet.<\/li>\n<li>In the script block of the <b>ForEach-Object<\/b> cmdlet, use the <b>Get-ItemProperty<\/b> cmdlet to retrieve the property values.<\/li>\n<li>Return to the original working location by using the <b>Pop-Location<\/b> cmdlet.<\/li>\n<\/ol>\n<p style=\"padding-left: 30px\"><b>Note<\/b>&nbsp;&nbsp;&nbsp; When you are typing the path to the specific registry key, remember that you can use tab expansion. The use of the Windows PowerShell tab expansion feature not only saves time typing, but it also invariably saves time troubleshooting mistyped commands. It is essential that you train yourself to use tab expansion everywhere it is available.<\/p>\n<p>The Get-RegistryKeyPropertiesAndValues.ps1 script follows the previous <i>Enumerating registry property values <\/i>steps, but it adds a bit of extra power to the equation by creating a custom object for each registry property\/value combination. The script creates a new custom object for each key\/property pair. To do this, the script creates the object inside the <b>Foreach-Object<\/b> cmdlet. The resulting object pipes to the <b>Format-Table<\/b> for display to the console. The script then returns to the original working location by using the <b>Pop-Location<\/b> cmdlet. The complete Get-RegistryKeyPropertiesAndValues.ps1 script is shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-RegistryKeyPropertiesAndValues.ps1<\/p>\n<p style=\"padding-left: 30px\">Push-Location<\/p>\n<p style=\"padding-left: 30px\">Set-Location &#8216;HKCU:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon&#8217;<\/p>\n<p style=\"padding-left: 30px\">Get-Item . |<\/p>\n<p style=\"padding-left: 30px\">Select-Object -ExpandProperty property |<\/p>\n<p style=\"padding-left: 30px\">ForEach-Object {<\/p>\n<p style=\"padding-left: 30px\">New-Object psobject -Property @{&#8220;property&#8221;=$_;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8220;Value&#8221; = (Get-ItemProperty -Path . -Name $_).$_}} |<\/p>\n<p style=\"padding-left: 30px\">Format-Table property, value -AutoSize<\/p>\n<p style=\"padding-left: 30px\">Pop-Location<\/p>\n<p style=\"padding-left: 30px\">It is rather easy to convert the above script to a function. The Get-RegistryKeyPropertiiesAndValues function appears here.<\/p>\n<p style=\"padding-left: 30px\">Get-RegistryKeyPropertiesAndValues Function<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Function Get-RegistryKeyPropertiesAndValues<\/p>\n<p style=\"padding-left: 30px\">{<\/p>\n<p style=\"padding-left: 30px\">&nbsp; &lt;#<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Synopsis<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function accepts a registry path and returns all reg key properties and values<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Description<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function returns registry key properies and values.<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Example<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Get-RegistryKeyPropertiesAndValues -path &#8216;HKCU:\\Volatile Environment&#8217;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Returns all of the registry property values under the \\volatile environment key<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Parameter path<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; The path to the registry key<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Notes<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; NAME:&nbsp; Get-RegistryKeyPropertiesAndValues<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; AUTHOR: ed wilson, msft<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; LASTEDIT: 05\/09\/2012 15:18:41<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; KEYWORDS: Operating System, Registry, Scripting Techniques, Getting Started<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; HSG: 5-11-12<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Link<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp; Http:\/\/www.ScriptingGuys.com\/blog<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#Requires -Version 2.0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Param(<\/p>\n<p style=\"padding-left: 30px\">&nbsp; [Parameter(Mandatory=$true)]<\/p>\n<p style=\"padding-left: 30px\">&nbsp; [string]$path)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Push-Location<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Set-Location -Path $path<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Get-Item . |<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Select-Object -ExpandProperty property |<\/p>\n<p style=\"padding-left: 30px\">&nbsp;ForEach-Object {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;New-Object psobject -Property @{&#8220;property&#8221;=$_;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; &#8220;Value&#8221; = (Get-ItemProperty -Path . -Name $_).$_}}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Pop-Location<\/p>\n<p style=\"padding-left: 30px\">} #end function Get-RegistryKeyPropertiesAndValues<\/p>\n<p>To use the <b>Get-RegistryKeyPropertiesAndValues<\/b> function to obtain registry key properties and their associated values, pass the path to it. For example, the image that follows illustrates the <i>Volatile Environment <\/i>registry key. On the right are a large number of registry key properties.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3644.hsg-5-11-12-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3644.hsg-5-11-12-03.png\" alt=\"Image of Registry Editor\" title=\"Image of Registry Editor\" \/><\/a><\/p>\n<p>Open the Windows PowerShell ISE and load the function by opening the script that contains it. Next load the function into memory by clicking the run button (or pressing F5). When it is loaded into memory, call the function by typing the function name in the immediate window and providing a path to a specific registry key. For this example, use the HKCU:\\Volatile Environment registry key (make sure you put quotation marks around the entire path to the registry key). Use the <b>Format-Table<\/b> cmdlet to display the property name and then the property value. The following command illustrates a typical command line.<\/p>\n<p style=\"padding-left: 30px\">Get-RegistryKeyPropertiesAndValues -path &#8216;HKCU:\\Volatile Environment&#8217; | ft property, value -AutoSize<\/p>\n<p>This technique is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8831.hsg-5-11-12-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8831.hsg-5-11-12-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>BW, that is all there is to obtaining the value of the registry property values under a specific registry key. Registry Week will continue tomorrow when I will talk about modifying registry property values.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to enumerate all the properties and their values under a registry key. &nbsp;Hey, Scripting Guy! I have a question. It seems that getting the property values under a registry key is a tedious process. It looks like I need to know the exact [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,31,26,3,4,45],"class_list":["post-9461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-operating-system","tag-registry","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to enumerate all the properties and their values under a registry key. &nbsp;Hey, Scripting Guy! I have a question. It seems that getting the property values under a registry key is a tedious process. It looks like I need to know the exact [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/9461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=9461"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/9461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=9461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=9461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=9461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}