通过powershell-批量卸载安装的系统补丁

针对incredibuild 在win7上更新补丁后编译报错的问题,解决方案是卸载掉安装的系统补丁(备注:以后大家的测试环境最好不要自动更新系统补丁)

 

通过powershell-批量卸载补丁操作步骤:

1、以管理员身份运行powershell

2、执行:Set-ExecutionPolicy RemoteSigned

3、输入Y后回车

4、Remove-Update.ps1脚本拷贝至C盘根目录,然后直接将C盘的该脚本拖入到powershell窗口中执行即可

 

脚本中:

$TimeOutDays=7 字段代表卸载多久之前时间安装的补丁

比如现在本地电脑时间为7月7日,配置为7天,这样就可以卸载7月1日-7月7日之间安装的系统补丁

 

cls

function Remove-Update {

$TimeOutDays=7   #天数配置

[int]$count = 0;

$hotfixes=(Get-HotFix | Sort-Object -Property installedon -Descending)

#$lis= (Get-HotFix | Sort-Object -Property installedon -Descending)

foreach ($hotfix in $hotfixes)

        {  $count = $count + 1              

           $installtime=$hotfix | Select-Object -ExpandProperty installedon           

           $daypan=((get-date)-$installtime).days

          # $lis= Get-HotFix | Sort-Object -Property installedon -Descending

           if ($TimeOutDays -gt $daypan )

              {  "Inside first if"

                $KBID = $hotfix.HotfixId.Replace("KB", "")

                write-host $kbid

                $RemovalCommand = "wusa.exe /uninstall /kb:$KBID /quiet /norestart"

                Write-Host "卸载 KB$KBID ,安装时间:"$installtime

                Invoke-Expression $RemovalCommand          

    while (@(Get-Process wusa -ErrorAction SilentlyContinue).Count -ne 0)         

            { Start-Sleep 3

              Write-Host "wusa.exe正在运行 ...卸载中..." }

      }  }

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值