用powershell 批量卸载 windows 更新

$KBID = "KB958488"
$KBID1 = "KB976902"

function Remove-Update {

$HotFixes = Get-HotFix

foreach ($HotFix in $HotFixes)
{

    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

用powershell 批量卸载 windows 更新,布布扣,bubuko.com

用powershell 批量卸载 windows 更新

上一篇:WPF TextBox 禁用,背景色属性触发不生效问题(显示白色)


下一篇:Linux系统上挂载Windows共享目录的步骤(附图)