/build/static/layout/Breadcrumb_cap_w.png

Script to add NoRemove property with Powershell

When i install Visual studio it is creating uninstall registry with different hive each time.

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ddd4bb47

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\2237a22

I need to find registry hive and need to add NoRemove=1

Please help me to correct this script

Set-ExecutionPolicy Unrestricted -Force

Set-Location "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"

Get-ChildItem | Where-Object { $_.DisplayName -eq "2237a22" } | New-Item NoRemove=1





1 Comment   [ + ] Show comment
  • You need to recurse through each hive and examine the DisplayName for your product, then write the key.

    Its a bit trick because you need to expand each item value for the DisplayName. But also handle the hive items which error, because the there is no item to expand.

    It's not as easy as you would think. - rileyz 5 years ago

Answers (1)

Posted by: rileyz 5 years ago
Red Belt
1

Here is something I knocked together, need to handle the "Select-Object : Property "DisplayName" cannot be found." errors, but its a good start.

$UninstallRegistryArray = (Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall).Name -replace 'HKEY_LOCAL_MACHINE','HKLM:'
Foreach ($Uninstall in $UninstallRegistryArray)
    {If ((Get-ItemProperty -Path $Uninstall | Select-Object -ExpandProperty 'DisplayName') -eq 'Name of App')
         {Write-Output 'Found the key! Do your command here to write your key.'}}
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ