03/10/2019 412 views

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



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.

All Answers


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.'}}
Answered 03/10/2019 by: rileyz
Red Belt