I’m trying to remove some keys from register based on an array of paths which I would search for a few keywords and want to delete the “Tree” where the subkey was found.
But after trying to figure it out, the script down below is not working.
Begin
{
$computerName = $env:computername
$Register = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computerName)
[array]$KeyToRemove="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","SOFTWARE\Classes\Installer\Products","SOFTWARE\Microsoft\OnlineManagement","SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products","SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components"
}
Process
{
foreach($chave in $KeyToRemove){
$RegisterKey = $Register.OpenSubkey($chave)
$NomeSubChaves = $RegisterKey.GetSubKeyNames() | ForEach-Object
{
$Value = $NomeSubChaves.GetValue($_)
}
$RegisterKey.GetValueNames() | ForEach-Object
{
$Value = $RegisterKey.GetValue($_)
"Value name: {0} had data: {1}" -f $_,$Value
}
}
}
Can anybody help me with this issue?
Thanks!