Server/Windows Server

[PowerShell] Windows 자동 업데이트

달빛에취하다 2022. 2. 24. 15:17

사내에서 Windows Server를 몇대 운용 중입니다. 가상 서버 4대, WAS, DB, WEB, AD, AD2, 격리 서버 등등..

 

업데이트 할때 마다 귀찮아서 여기저기 찾아서 PowerShell 짜집기 했습니다.

 

사용 모듈 : PSWindowsUpdate 

How to Use PowerShell to Manage Windows Updates (parallels.com)
Windows. Powershell 모듈을 이용하여 Windows Update 하기 (PSWindowsUpdate) :: 페푸리의 Office Server 이야기 (limcm.kr)
PSWindowsUpdate 파워쉘 모듈 | Windows 업데이트 관리 윈도우 OS 허브 (woshub.com)

 

Manage Windows Updates with PSWindowsUpdate PowerShell Module | Windows OS Hub

You can use the PSWindowsUpdate PowerShell module to manage Windows updates from the command line. The PSWindowsUpdate module is not built into Windows and is available for installation from the…

woshub.com

 

해당 모듈이 명령어 만으로 설치되지 않아서 패키지 형태로 묶어서 사용 중입니다.

(첨부파일 참조)

 

업데이트 전체 설치 및 자동 재부팅으로 되어 있습니다.

 

사용하실 분들은 Windowsupdate.bat의 경로 를 수정해 주시고 관리자 권한으로 실행하셔야 합니다.

 

* WindowsUpdate.bat

@echo off 

if not exist "%WINDIR%\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate" ( md "%WINDIR%\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate" & XCOPY D:\_WindowsUpdate\PSWindowsUpdate  %WINDIR%\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate /s /h /e /k
) 
  
powershell.exe -nologo -executionpolicy bypass -noprofile -file "D:\_WindowsUpdate\WindowsUpdate.ps1" >> D:\_WindowsUpdate\LOG\%computername%_%date%.txt

exit

 

* WindowsUpdate.ps1

#Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy RemoteSigned -scope process -Force

Import-Module -Name PSWindowsUpdate

Get-WindowsUpdate

Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot

 

_WindowsUpdate.zip
0.12MB