Error on trying to search and delete Register SubKeyTree

Welcome Forums General PowerShell Q&A Error on trying to search and delete Register SubKeyTree

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
3 years ago.

  • Author
    Posts
  • #38701

    Participant
    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    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

    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Can you be more specific than "not working?"

The topic ‘Error on trying to search and delete Register SubKeyTree’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort