您的位置:首页 > 运维架构 > Shell

用powershell 批量卸载 windows 更新

2014-02-28 15:57 330 查看
$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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: