利用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 }
