Notice
Recent Posts
Recent Comments
04-16 18:09
관리 메뉴

Black&White

mbsacli 를 이용하여 윈도우 자동 업데이트 하기 본문

Windows

mbsacli 를 이용하여 윈도우 자동 업데이트 하기

V.E.N 2016. 4. 19. 11:41

mbsacli 를 이용하여 오프라인상태에서 윈도우 업데이트 체크하기 를 참고




1) 먼저 MBSAcli.exe 를 이용하여 updates.xml 파일을 생성(아래 명령 참고

MBSACLI /xmlout /catalog c:\temp\wsusscn2.cab /unicode > c:\temp\updates.xml


2) 아래 스크립트를 파일명 GetUpdates.ps1 으로 저장한다.


$UpdateXML = "updates.xml"

$toFolder = "c:\temp\"

$installFile = $toFolder + "\Updates_Install.bat"


#Initialize webclient for downloading files

$webclient = New-Object Net.Webclient

$webClient.UseDefaultCredentials = $true


# Get the content of the XML file

$Updates = [xml](Get-Content $UpdateXML)


"@Echo Off" | Out-File $installFile

"REM This will install all patches" | Out-File $installFile -Append


foreach ($Check in $Updates.XMLOut.Check)

{

Write-Host "Checking for", $Check.Name

Write-Host $Check.Advice.ToString()


#Checking for files to download

foreach ($UpdateData in $Check.Detail.UpdateData)

{

if ($UpdateData.IsInstalled -eq $false)

{

Write-Host "Download the file for KB", $UpdateData.KBID

Write-Host "Starting download ", $UpdateData.Title, "."

$url = [URI]$UpdateData.References.DownloadURL

$fileName = $url.Segments[$url.Segments.Count - 1]

$toFile = $toFolder +"\"+ $fileName

$webClient.DownloadFile($url, $toFile)

Write-Host "Done downloading"


"@ECHO Starting installing "+ $fileName | Out-File $installFile -Append

if ($fileName.EndsWith(".msu"))

{

"wusa.exe "+ $fileName + " /quiet /norestart /log:%SystemRoot%\Temp\KB"+$UpdateData.KBID+".log" | Out-File $installFile -Append

}

elseif ($fileName.EndsWith(".cab"))

{

"start /wait pkgmgr.exe /ip /m:"+ $fileName + " /quiet /nostart /l:%SystemRoot%\Temp\KB"+$UpdateData.KBID+".log" | Out-File $installFile -Append

}

else

{

$fileName + " /passive /norestart /log %SystemRoot%\Temp\KB"+$UpdateData.KBID+".log" | Out-File $installFile -Append

}

"@ECHO Installation returned %ERRORLEVEL%" | Out-File $installFile -Append

"@ECHO." | Out-File $installFile -Append

Write-Host

}

}


Write-Host

}


3) cmd 창에서 powershell .\GetUpdates.ps1 을 실행한다.


이때 에러가 발생한다면, powershell 에서 서명된 스크립트의 실행을 허용하도록 설정을 바꿔줘야 한다.


cmd 창에서 아래 명령을 실행후, 결과에 Restricted 로 나온다면, 


powershell get-executionpolicy


다시 cmd 창에서 아래 명령을 실행한다.

powershell set-executionpolicy remotesigned


이렇게 powershell 설정을 powershell .\GetUpdates.ps1 을 실행한다.



   업데이트게 있다면

4) Updates_Install.bat 를 실행한다.

Comments