{"id":51903,"date":"2009-11-30T00:01:00","date_gmt":"2009-11-30T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/11\/30\/hey-scripting-guy-can-i-change-the-default-value-of-a-registry-key-on-multiple-computers\/"},"modified":"2009-11-30T00:01:00","modified_gmt":"2009-11-30T00:01:00","slug":"hey-scripting-guy-can-i-change-the-default-value-of-a-registry-key-on-multiple-computers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-i-change-the-default-value-of-a-registry-key-on-multiple-computers\/","title":{"rendered":"Hey, Scripting Guy! Can I Change the Default Value of a Registry Key on Multiple Computers?"},"content":{"rendered":"<p><!-- AddThis Button BEGIN --><\/p>\n<p><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a>     <\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\">Hey Scripting Guy! I have a problem. There is a registry key on several computers that has a default value of &ldquo;default.&rdquo; I need to be able to change that default value. I searched the Hey, Scripting Guy! blog and came up with an <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2008\/06\/24\/hey-scripting-guy-how-can-i-change-a-registry-value-named-default.aspx\"><font face=\"Segoe\">article written for VBScript<\/font><\/a>. I know I can use WMI in Windows PowerShell 2.0, but the process looks complicated. Can you explain it to me? Is there an easier way?<\/p>\n<p class=\"MsoNormal\">&#8212; CS<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello CS, Microsoft Scripting Guy Ed Wilson here. Right now I have my Zune HD cranked up all the way while listening to an old <a href=\"http:\/\/en.wikipedia.org\/wiki\/Rolling_stones\"><font face=\"Segoe\">Rolling Stones<\/font><\/a> recording of a song they sang with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Buddy_Guy\"><font face=\"Segoe\">Buddy Guy<\/font><\/a>. The cool thing about the Rolling Stones is they have recorded so much music. I have been listening to the Rolling Stones now for the last eight hours while I have been answering <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> e-mail and talking to people on my personal <a href=\"http:\/\/www.facebook.com\/Mr.Ed.Wilson\"><font face=\"Segoe\">Facebook<\/font><\/a> page and on the Scripting Guys&rsquo; <a href=\"https:\/\/twitter.com\/scriptingguys\/\"><font face=\"Segoe\">Twitter<\/font><\/a> page. On Facebook, I have been talking to Brandon, a Microsoft MVP, about doing a couple of guest articles related to his <span lang=\"EN\"><a href=\"http:\/\/bsonposh.com\/\"><font face=\"Segoe\">bsonposh module<\/font><\/a>. On Twitter, I have been talking to many people about this week&rsquo;s series of Hey, Scripting Guy! articles. <\/p>\n<p><\/span><\/p>\n<p class=\"Readeraidonly\"><span lang=\"EN\">Portions of today&rsquo;s Hey, Scripting Guy! post appeared previously in the 2008 Microsoft Press book, <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-TM-Scripting-Guide\/dp\/0735622795\"><font face=\"Segoe\">Windows PowerShell Scripting Guide<\/font><\/a>. <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\">CS, the script from the post, &ldquo;How Can I Change a Registry Value Named (Default)?&rdquo;, uses the WMI class that is named <b>StdRegProv<\/b>. Things are confusing from the beginning. The name of the WMI class is <b>StdRegProv<\/b>? That looks like the name of a WMI provider, not the name of a WMI class. Most of the WMI classes we use begin with <b>Win32<\/b>, and the names are more easily understood. The second thing you will notice about the SetDefaultRegistryStringValue.vbs script is that the WMI class is located in the <b>rootdefault<\/b> WMI namespace. Interestingly enough, <b>rootdefault<\/b> is not the default WMI namespace. <b>Rootcimv2<\/b> is the default WMI namespace on every Windows operating system made since Windows NT 4.0. Beginning with Windows Vista, the WMI team also placed a copy of the <b>StdRegProv<\/b> WMI class in <b>rootcimv2<\/b>. If all of your computers are Windows Vista and later, you can ignore the version of the <b>StdRegProv<\/b> in <b>rootdefault<\/b> and only use the one from the <b>rootcimv2<\/b> WMI namespace. <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\">The most confusing thing about the <b>StdRegProv<\/b> WMI class is that each data type in the registry requires a different method. These methods are <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa393664(VS.85).aspx\"><font face=\"Segoe\">documented on MSDN<\/font><\/a>. In this script the <b>SetStringValue<\/b> method is used to assign a new value to a key. For information about using the <b>StdRegProv<\/b> WMI class from within Windows PowerShell, refer to <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/01\/07\/how-can-i-change-my-internet-explorer-home-page.aspx\"><font face=\"Segoe\">How Can I Change My Internet Explorer Home Page<\/font><\/a>. The complete SetDefaultRegistryStringValue.vbs script is shown here. <\/p>\n<p><\/span><\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>SetDefaultRegistryStringValue.vbs<\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span lang=\"EN\"><font face=\"Lucida Sans Typewriter\">Const HKEY_CURRENT_USER = &amp;H80000001<\/p>\n<p>strComputer = &#8220;.&#8221;<\/p>\n<p>Set objRegistry = GetObject(&#8220;winmgmts:\\&#8221; &amp; strComputer &amp; &#8220;rootdefault:StdRegProv&#8221;)<\/p>\n<p>strKeyPath = &#8220;ScriptCenter&#8221;<br>strValueName = &#8220;&#8221;<br>strValue = &#8220;http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx&#8221;<\/p>\n<p>objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">CS, an easier way to work with the registry by using Windows PowerShell is to use the registry provider. The registry provider provides a consistent and easy way to work with the registry from within Windows PowerShell. Using the registry provider, you can search the registry, create new registry keys, delete existing registry keys, and modify values and access control lists (ACLs) from within Windows PowerShell. Windows PowerShell creates two PSDrives by default. To identify the PSDrives supplied by the registry provider, you can use the <b>Get-PSDrive<\/b> cmdlet, and pipeline the resulting objects into the <b>Where-Object<\/b> cmdlet and filter on the <b>provider<\/b> property while supplying a value that is like the word &ldquo;registry.&rdquo; This command is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><span lang=\"EN\"><font face=\"Lucida Sans Typewriter\">get-psDrive | where {$_.Provider -like &#8220;*registry*&#8221;}<\/font><\/span><\/p>\n<p class=\"MsoNormal\">The resulting list of PSDrives is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><span lang=\"EN\"><font face=\"Lucida Sans Typewriter\">Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Provider<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Root<span>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>CurrentLocation<br>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8212;&#8212;<br>HKCU<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Registry<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>HKEY_CURRENT_USER<br>HKLM<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Registry<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>HKEY_LOCAL_MACHINE<\/font><\/span><\/p>\n<p class=\"MsoNormal\">Now that you know which registry drives exist (you can add additional registry drives by using the <b>Add-PSDrive<\/b> cmdlet), you can use the <b>Set-Item<\/b> cmdlet to assign a value to the default registry key. Suppose you have the registry key, HKEY_CURRENT_USERSoftwareScriptingGuys, that has an empty default value as seen here:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of registry key with empty default value\" alt=\"Image of registry key with empty default value\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1130\/hsg-11-30-09-01.jpg\" width=\"600\" height=\"420\"><\/p>\n<p class=\"MsoNormal\"><br>To assign a value, you can write a script similar to <span lang=\"EN\">SetDefaultRegistryStringValue.vbs in VBScript, or you can emulate that methodology in Windows PowerShell. But the easier way is to<\/span> use the registry provider for Windows PowerShell. Using the HKCU drive in Windows PowerShell, you can use the same cmdlets you use to work with the filesystem. The <b>Set-Item<\/b> cmdlet writes information. To provide a value for the ScriptingGuys registry key, specify the path, the value, and the type of value you are assigning. To write the string &ldquo;MyNewValue&rdquo; to the registry key, use the following command:<\/p>\n<p class=\"CodeBlockScreened\"><span lang=\"EN\"><font face=\"Lucida Sans Typewriter\">Set-Item -Path HKCU:SoftwareScriptingGuys -Value &#8220;MyNewValue&#8221; -Type string<\/font><\/span><\/p>\n<p class=\"MsoNormal\">The revised registry key now has a value for <b>(Default)<\/b>:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of resitry key with default value\" alt=\"Image of resitry key with default value\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1130\/hsg-11-30-09-02.jpg\" width=\"600\" height=\"420\"><\/p>\n<p class=\"MsoNormal\"><br>CS you said you need to make the change on multiple computers. Using Windows PowerShell 1.0 I normally fell back to the StdRegProv WMI class to do that. But in Windows PowerShell 2.0 you can use the Invoke-Command cmdlet to execute a standard Windows PowerShell command on a remote computer. Because we need to assign a registry value to a key that is in the HKEY_CURRENT_USERSoftwareScriptingGuys hive things could get a bit confusing. This is because I am logged onto my workstation as NwtradersEd. I want to target a computer that has NwtradersAdministrator logged on. My current user hive on the remote machine is different than the current user that is logged on. To work around this, all we need to do is supply alternate credentials when we invoke the command. The command to do this is seen here (this command is one line)<\/p>\n<p class=\"CodeBlockScreened\"><span lang=\"EN\"><font face=\"Lucida Sans Typewriter\">PS C:&gt; Invoke-Command -computer Win7-Pc -script { Set-Item -Path HKCU:SoftwareScriptingGuys -Value &#8220;MyNewValue&#8221; &ndash;Type string } -Credential nwtradersadministrator<\/font><\/span><\/p>\n<p class=\"MsoNormal\">The credential dialog box appears and prompts you for the password:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of credential dialog box\" alt=\"Image of credential dialog box\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1130\/hsg-11-30-09-03.jpg\" width=\"326\" height=\"257\"><\/p>\n<p class=\"MsoNormal\"><br>After the command has run on the remote computer, we use Remote Desktop to browse the registry as the administrator. As seen in the following image, the registry key has been changed:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of changed registry key\" alt=\"Image of changed registry key\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1130\/hsg-11-30-09-04.jpg\" width=\"600\" height=\"430\"><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">CS, that is all there is to adding a value to a registry key with the name of <b>(Default)<\/b>. Registry Week will continue tomorrow when we will talk about&hellip;wait a minute. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\"><font face=\"Segoe\">Facebook<\/font><\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p><!-- AddThis Button END --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey Scripting Guy! I have a problem. There is a registry key on several computers that has a default value of &ldquo;default.&rdquo; I need to be able to change that default value. I searched the Hey, Scripting Guy! blog and came up with an article written for VBScript. I know I can use WMI [&hellip;]<\/p>\n","protected":false},"author":595,"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-51903","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>&nbsp; Hey Scripting Guy! I have a problem. There is a registry key on several computers that has a default value of &ldquo;default.&rdquo; I need to be able to change that default value. I searched the Hey, Scripting Guy! blog and came up with an article written for VBScript. I know I can use WMI [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51903","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=51903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51903\/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=51903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}