Powershell 安装指定离线更新补丁


利用powershell 升级WIN7_64到POwershell 到5.1版本 当然也可以安装其它离线补丁,环境是域,当前登陆的用户是域管理员,利用WUSA和DISM安装,如果不解压直接运行.MSU文件是一闪而过,不会安装任何东西

 1 $pc='PC03'
 2 
 3 if((Get-HotFix -Id KB3191566 -ComputerName $pc) -ne $null){
 4 
 5 Write-Warning  "$pc 已经安装了PS 5.1补丁"
 6 
 7 }else{
 8 
 9 Write-Warning  "$pc  需要更新!"
10 
11 Write-Warning  "$pc 复制文件"
12 Copy-Item -Path '\\sccm01\G$\PowerShell\Win7AndW2K8R2-KB3191566-x64' -Destination \\$pc\D$ -Recurse -force
13 
14 Invoke-Command  -ComputerName $pc  -ScriptBlock{
15 
16 Start-Process -FilePath 'wusa.exe' -ArgumentList "d:\Win7AndW2K8R2-KB3191566-x64\Win7AndW2K8R2-KB3191566-x64.msu /extract:d:\Win7AndW2K8R2-KB3191566-x64" -Verb RunAs  -Wait -Passthru -WindowStyle Hidden
17 Write-Warning  "$pc 解压文件"
18 
19 Get-ChildItem -Path "d:\Win7AndW2K8R2-KB3191566-x64" -Filter "*.cab"|ForEach-Object{
20 
21 $cabPath="d:\Win7AndW2K8R2-KB3191566-x64\"+$_.Name
22 
23 Write-Warning "安装更新: $cabPath"
24 
25 Start-Process -WindowStyle Hidden -FilePath 'dism.exe' -ArgumentList "/online /add-package /PackagePath:$cabPath /IgnoreCheck /quiet /norestart" -Verb RunAs -Wait -PassThru
26 
27 }
28 
29 Write-Warning  "$pc 检查补丁文件是否已安装!"
30 Get-HotFix -Id KB2809215,KB2872035,KB2872047,KB3033929,KB3191566 |Format-Table
31 
32 Remove-Item -Path 'd:\Win7AndW2K8R2-KB3191566-x64\' -Force -recurse
33 
34 Write-Warning  "$pc 删除临时文件"
35 }
36 
37 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM