且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell:删除所有包含字符串的注册表项

更新时间:2023-11-14 15:36:58

试试下面的脚本:

$RE = 'Python35'
$Key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components'
Get-ChildItem $Key -Rec -EA SilentlyContinue | ForEach-Object {
   $CurrentKey = (Get-ItemProperty -Path $_.PsPath)
   If ($CurrentKey -match $RE){
     $CurrentKey|Remove-Item -Force -Whatif
   }
}

如果输出看起来没问题,从 Remove-Item

If the output looks OK remove the -WhatIf paramter from Remove-Item