Error on trying to search and delete Register SubKeyTree

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 4 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38701
    Profile photo of pulgalipe
    pulgalipe
    Participant

    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!

    #38864
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Can you be more specific than "not working?"

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.