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
Answers (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.'}}
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