批量删除Windows补丁

将以下代码保存为E:a.ps1文件,打开cmd分三步输入以下命令

(1)PowerShell 

(2)Set-ExecutionPolicy RemoteSigned 

(3)E:a.ps1

核心思想:windows 的"wusa.exe"和ps1批处理文件

$KBID = "KB958488" 
$KBID1 = "KB976902"
cls
function Remove-Update {

$HotFixes = Get-HotFix
[int]$count = 0;
foreach ($HotFix in $HotFixes) 
{
    $count = $count + 1
    Write-Host $count / $HotFixes.Count
    if (($KBID -ne $HotFix.HotfixId) -and ($KBID1 -ne $HotFix.HotfixId)) 
    { 
        "Inside first if" 
        $KBID = $HotFix.HotfixId.Replace("KB", "") 
        $RemovalCommand = "wusa.exe /uninstall /kb:$KBID /quiet /norestart" 
        Write-Host "Removing $KBID from the target." 
        Invoke-Expression $RemovalCommand 
        
    } 
    
    if ($KBID -match "All") 
    { 
        $KBNumber = $HotFix.HotfixId.Replace("KB", "") 
        $RemovalCommand = "wusa.exe /uninstall /kb:$KBNumber /quiet /norestart" 
        Write-Host "Removing update $KBNumber from the target." 
        Invoke-Expression $RemovalCommand 
        
    } 
    
    if ($KBID -match "Security") 
    { 
        if ($HotFix.Description -match "Security") 
        { 
        
            $KBSecurity = $HotFix.HotfixId.Replace("KB", "") 
            $RemovalCommand = "wusa.exe /uninstall /kb:$KBSecurity /quiet /norestart" 
            Write-Host "Removing Security Update $KBSecurity from the target." 
            Invoke-Expression $RemovalCommand 
        } 
    } 
   

    while (@(Get-Process wusa -ErrorAction SilentlyContinue).Count -ne 0) 
    { 
        Start-Sleep 3 
        Write-Host "Waiting for update removal to finish ..." 
    } 
}

}

Remove-Update


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值