{"id":10751,"date":"2012-03-16T00:01:00","date_gmt":"2012-03-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/03\/16\/use-powershell-to-edit-the-registry-on-remote-computers\/"},"modified":"2012-03-16T00:01:00","modified_gmt":"2012-03-16T00:01:00","slug":"use-powershell-to-edit-the-registry-on-remote-computers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-edit-the-registry-on-remote-computers\/","title":{"rendered":"Use PowerShell to Edit the Registry on Remote Computers"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to edit the registry on remote computers.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. In Wednesday&rsquo;s <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/03\/06\/windows-powershell-for-the-busy-admin.aspx\" target=\"_blank\">PowerShell Essentials live meeting<\/a> presentation, one of the questions revolved around working with the registry on a remote computer. While there are lots of ways to work with the registry on a remote computer, including using Windows Management Instrumentation, or .NET Framework classes, I like to use a combination of Windows PowerShell remoting and the Windows PowerShell registry provider because it is easier. In fact, by using Windows PowerShell remoting, it is just as easy to work with the remote registry as it is to work with a local registry.<\/p>\n<p><b>Note<\/b>&nbsp;&nbsp;&nbsp;<br \/> For a good introduction to using Windows PowerShell to work with the registry, see <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/04\/20\/hey-scripting-guy-april-20-2010.aspx\" target=\"_blank\">The Scripting Wife, Windows PowerShell, and the Registry<\/a>. <br \/> For more advanced topics, check out some of the other <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/tags\/operating+system+\/registry\/Windows+PowerShell\/default.aspx\" target=\"_blank\">blog posts about the registry<\/a> in the Hey, Scripting Guy! Blog archives. There you will find blogs such as:<\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/11\/30\/hey-scripting-guy-november-30-2009.aspx\" target=\"_blank\">Can I Change the Default Value of a Registry Key on Multiple Computers?<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/12\/01\/hey-scripting-guy-december-1-2009.aspx\" target=\"_blank\">How Can I List All User Profiles on a Remote Computer?<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/12\/02\/hey-scripting-guy-december-2-2009.aspx\" target=\"_blank\">Can I Use the Registry to Retrieve a List of the Most Recently Run Programs?<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/12\/03\/hey-scripting-guy-december-3-2009.aspx\" target=\"_blank\">How Can I Change Browser History Settings via the Registry?<\/a><\/li>\n<\/ul>\n<p>Suppose I want to create a new registry key under HKEY_CURRENT_USER under the Software key, and I want to call it <b>HSG<\/b><i>. <\/i>The registry location (for the target <b>HSG<\/b><i>) <\/i>is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1641.hsg-3-16-12-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1641.hsg-3-16-12-02.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>To create the new registry key, I use the four steps:<\/p>\n<ol>\n<li>I use the <b>Push-Location<\/b> cmdlet (<b>pushd<\/b> is an alias) to store my current location.<\/li>\n<li>I use the <b>Set-Location<\/b> cmdlet to change my working location to the HKCU:\\Software location.<\/li>\n<li>I use the <b>New-Item<\/b> cmdlet to create the new registry key.<\/li>\n<li>I use the <b>Pop-Location<\/b> cmdlet (<b>popd<\/b> is an alias) to return to my current location.<\/li>\n<\/ol>\n<p>The commands are shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; pushd<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Set-Location HKCU:\\Software<\/p>\n<p style=\"padding-left: 30px\">PS HKCU:\\Software&gt; New-Item -Name HSG<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Hive: HKEY_CURRENT_USER\\Software<\/p>\n<p style=\"padding-left: 30px\">SKC&nbsp; VC Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property<\/p>\n<p style=\"padding-left: 30px\">&#8212;&nbsp; &#8212; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">&nbsp; 0&nbsp;&nbsp; 0 HSG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">PS HKCU:\\Software&gt; popd<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The newly created registry key is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5265.hsg-3-16-12-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5265.hsg-3-16-12-03.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>To add a registry property value, I use the <b>New-ItemProperty<\/b> cmdlet. I perform the same basic steps I used to create the registry key, but I use the <b>New-ITemProperty<\/b> cmdlet instead of the <b>New-Item<\/b> cmdlet, as follows:<\/p>\n<ol>\n<li>I use the <b>Push-Location<\/b> cmdlet to store my current location.<\/li>\n<li>I use the <b>Set-Location<\/b> cmdlet to change my working location to the HKCU:\\Software location.<\/li>\n<li>I use the <b>New-ItemProperty<\/b> cmdlet to create the new registry property. I specify the <b>Name<\/b><i>, <\/i><b>Path<\/b><i>, <\/i><b>Value<\/b><i>, <\/i>and <b>PropertyType<\/b><i>. <\/i><\/li>\n<li>I use the <b>Pop-Location<\/b> cmdlet to return to my current location.<\/li>\n<\/ol>\n<p>The use of these techniques is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; pushd<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Set-Location HKCU:\\Software<\/p>\n<p style=\"padding-left: 30px\">PS HKCU:\\Software&gt; New-ItemProperty -Name forscripting -PropertyType string -path hsg -Value &#8220;PowerShell Rocks&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PSPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.PowerShell.Core\\Registry::HKEY_CURRENT_USER\\Software\\hsg<\/p>\n<p style=\"padding-left: 30px\">PSParentPath : Microsoft.PowerShell.Core\\Registry::HKEY_CURRENT_USER\\Software<\/p>\n<p style=\"padding-left: 30px\">PSChildName&nbsp; : hsg<\/p>\n<p style=\"padding-left: 30px\">PSDrive&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : HKCU<\/p>\n<p style=\"padding-left: 30px\">PSProvider&nbsp;&nbsp; : Microsoft.PowerShell.Core\\Registry<\/p>\n<p style=\"padding-left: 30px\">forscripting : PowerShell Rocks<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS HKCU:\\Software&gt; popd<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p>The newly created registry property is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2821.hsg-3-16-12-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2821.hsg-3-16-12-04.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>After I have done all this locally, it is really easy to do it against a remote computer. I can do it by using Windows PowerShell remoting by using the following steps:<\/p>\n<ol>\n<li>I use the <b>Get-Credential <\/b>cmdlet to retrieve a credential object to use to make a remote connection.<\/li>\n<li>I use the <b>Enter-PSSession <\/b>cmdlet to enter a remote PS Session.<\/li>\n<li>I use the P<b>ush-Location<\/b> cmdlet to store my current location.<\/li>\n<li>I use the <b>Set-Location<\/b> cmdlet to change my working location to the HKCU:\\Software location.<\/li>\n<li>I use the <b>New-Item<\/b> cmdlet to create the new registry key.<\/li>\n<li>I use the <b>New-ItemProperty<\/b> cmdlet to create the new registry property. I specify the <b>Name<\/b><i>, <\/i><b>Path<\/b><i>, <\/i><b>Value<\/b><i>, <\/i>and <b>PropertyType<\/b><i>. <\/i><\/li>\n<li>I use the <b>Pop-Location<\/b> cmdlet to return to my previous location.<\/li>\n<li>I use the EXIT command to leave the remote PS Session.<\/li>\n<\/ol>\n<p>The following image illustrates this technique.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2783.hsg-3-16-12-05.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2783.hsg-3-16-12-05.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I then use Remote Desktop to connect to the remote server to verify that the registry key and property are updated. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5543.hsg-3-16-12-06.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5543.hsg-3-16-12-06.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>Well, that is about it for creating a remote registry key. Join me tomorrow, when I will talk about doing this in a single command&mdash;a scenario that is useful when you need to make changes on multiple computers.<\/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, talks about using Windows PowerShell to edit the registry on remote computers. Microsoft Scripting Guy, Ed Wilson, is here. In Wednesday&rsquo;s PowerShell Essentials live meeting presentation, one of the questions revolved around working with the registry on a remote computer. While there are lots of ways to work with [&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":[31,26,3,45],"class_list":["post-10751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-registry","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to edit the registry on remote computers. Microsoft Scripting Guy, Ed Wilson, is here. In Wednesday&rsquo;s PowerShell Essentials live meeting presentation, one of the questions revolved around working with the registry on a remote computer. While there are lots of ways to work with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/10751","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=10751"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/10751\/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=10751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=10751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=10751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}