{"id":3259,"date":"2022-05-07T13:21:54","date_gmt":"2022-05-07T11:21:54","guid":{"rendered":"https:\/\/leeryanrs.com\/?p=3259"},"modified":"2022-05-07T13:21:54","modified_gmt":"2022-05-07T11:21:54","slug":"replace-registry-keys","status":"publish","type":"post","link":"https:\/\/leeryanrs.com\/?p=3259","title":{"rendered":"Replace registry keys"},"content":{"rendered":"\n<p>I was recently tasked with migrating a software which had all of it&#8217;s configuration stored in the registry. The only way to update it &#8220;officially&#8221; was by uninstalling and reinstalling the whole suite, since this would take too long for 30 machines, I decided to script it to quicken things up. <\/p>\n\n\n\n<p>The way this works is by using the PowerShell functionality to search the registry &#8211; <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">foreach ($a in Get-ChildItem -Path \u2018HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\u2019 -Recurse) {\n  $a.Property | Where-Object {\n    $a.GetValue($_) -Like \u201c*value123*\u201d\n  } | ForEach-Object {\n    $CurrentValue = $a.GetValue($_)\n    $ReplacedValue = $CurrentValue.Replace(\u201cvalue123\", \u201cvalue1234\u201d)\n    Write-Output \u201cChanging value of $a\\$_ from \u2018$CurrentValue\u2019 to \u2018$ReplacedValue\u2019\u201d\n    Set-ItemProperty -Path Registry::$a -Name $_ -Value $ReplacedValue\n  }\n}<\/pre>\n\n\n\n<p>The script explained &#8211; <\/p>\n\n\n\n<p>i) It is searching in the Installer path with -Recurse, this means all the folder underneath it also.<\/p>\n\n\n\n<p>ii) GetValue &#8211; This is going to first build the search index with any registry key containing value123. It will find values such as https:\/\/value123.domain.com or just value123 alone.<\/p>\n\n\n\n<p>iii) ReplacedValue &#8211; We are giving it the value123 to identify and then replace it with value1234. It will not replace the whole string https:\/\/value123.domain.com, it will just replace it to https:\/\/value1234.domain.com<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>I hope this comes in handy for anyone searching to do something similar!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently tasked with migrating a software which had all of it&#8217;s configuration stored in the registry. The only way to update it &#8220;officially&#8221; was by uninstalling and reinstalling the whole suite, since this would take too long for 30 machines, I decided to script it to quicken things up. The way this works [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[33,38,40,51],"class_list":["post-3259","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-keys","tag-powershell","tag-registry","tag-windows"],"_links":{"self":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts\/3259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3259"}],"version-history":[{"count":0,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts\/3259\/revisions"}],"wp:attachment":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}