Computer >> 컴퓨터 >  >> 시스템 >> Windows

PowerShell 스크립트로 Windows 10 최신 패치 정보 확인하는 방법

Windows 10 시스템에 최신 누적 업데이트가 설치되어 있는지 확인하려면 대부분의 사용자가 Windows 10 업데이트 기록 페이지를 찾아봅니다. 이번 글에서는 PowerShell 스크립트를 사용해 Windows 10의 현재 패치 정보를 가져오는 방법을 소개합니다.

PowerShell 스크립트로 Windows 10 최신 패치 정보 확인하는 방법

Windows 업데이트 상태를 확인하는 PowerShell 스크립트

이 PowerShell 스크립트를 활용하면 Windows 10 컴퓨터가 현재 어떤 OS 빌드를 실행 중인지, 그리고 해당 장치에 제공되는 최신 업데이트가 무엇인지 한눈에 파악할 수 있습니다. 나아가 현재 사용 중인 Windows 10 버전에 대해 Microsoft가 배포한 모든 Windows 업데이트 목록까지 조회할 수 있습니다.

스크립트를 실행하면 다음과 같은 정보가 표시됩니다.

  • 현재 OS 버전
  • 현재 OS 에디션
  • 현재 OS 빌드 번호
  • 해당 빌드 번호와 일치하는 설치된 업데이트, KB 번호 및 정보 페이지 링크
  • 해당 OS 버전에 제공되는 최신 업데이트

PowerShell 스크립트로 Windows 10의 현재 패치 정보를 가져오려면 아래 GitHub 코드를 활용해 스크립트를 생성한 뒤 실행해야 합니다.

[CmdletBinding()]
Param(
[switch]$ListAllAvailable,
[switch]$ExcludePreview,
[switch]$ExcludeOutofBand
)
$ProgressPreference = 'SilentlyContinue'
$URI = "https://aka.ms/WindowsUpdateHistory" # Windows 10 release history

Function Get-MyWindowsVersion {
[CmdletBinding()]
Param
(
$ComputerName = $env:COMPUTERNAME
)

$Table = New-Object System.Data.DataTable
$Table.Columns.AddRange(@("ComputerName","Windows Edition","Version","OS Build"))
$ProductName = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ProductName).ProductName
Try
{
$Version = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID -ErrorAction Stop).ReleaseID
}
Catch
{
$Version = "N/A"
}
$CurrentBuild = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name CurrentBuild).CurrentBuild
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
$OSVersion = $CurrentBuild + "." + $UBR
$TempTable = New-Object System.Data.DataTable
$TempTable.Columns.AddRange(@("ComputerName","Windows Edition","Version","OS Build"))
[void]$TempTable.Rows.Add($env:COMPUTERNAME,$ProductName,$Version,$OSVersion)

Return $TempTable
}

Function Convert-ParsedArray {
Param($Array)

$ArrayList = New-Object System.Collections.ArrayList
foreach ($item in $Array)
{
[void]$ArrayList.Add([PSCustomObject]@{
Update = $item.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - ')
KB = "KB" + $item.href.Split('/')[-1]
InfoURL = "https://support.microsoft.com" + $item.href
OSBuild = $item.outerHTML.Split('(OS ')[1].Split()[1] # Just for sorting
})
}
Return $ArrayList
}

If ($PSVersionTable.PSVersion.Major -ge 6)
{
$Response = Invoke-WebRequest -Uri $URI -ErrorAction Stop
}
else
{
$Response = Invoke-WebRequest -Uri $URI -UseBasicParsing -ErrorAction Stop
}

If (!($Response.Links))
{ throw "Response was not parsed as HTML"}
$VersionDataRaw = $Response.Links | where {$_.outerHTML -match "supLeftNavLink" -and $_.outerHTML -match "KB"}
$CurrentWindowsVersion = Get-MyWindowsVersion -ErrorAction Stop

If ($ListAllAvailable)
{
If ($ExcludePreview -and $ExcludeOutofBand)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview" -and $_.outerHTML -notmatch "Out-of-band"}
}
ElseIf ($ExcludePreview)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview"}
}
ElseIf ($ExcludeOutofBand)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band"}
}
Else
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0]}
}
$UniqueList = (Convert-ParsedArray -Array $AllAvailable) | Sort OSBuild -Descending -Unique
$Table = New-Object System.Data.DataTable
[void]$Table.Columns.AddRange(@('Update','KB','InfoURL'))
foreach ($Update in $UniqueList)
{
[void]$Table.Rows.Add(
$Update.Update,
$Update.KB,
$Update.InfoURL
)
}
Return $Table
}

$CurrentPatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'} | Select -First 1
If ($ExcludePreview -and $ExcludeOutofBand)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band" -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludePreview)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludeOutofBand)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band"} | Select -First 1
}
Else
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0]} | Select -First 1
}


$Table = New-Object System.Data.DataTable
[void]$Table.Columns.AddRange(@('OSVersion','OSEdition','OSBuild','CurrentInstalledUpdate','CurrentInstalledUpdateKB','CurrentInstalledUpdateInfoURL','LatestAvailableUpdate','LastestAvailableUpdateKB','LastestAvailableUpdateInfoURL'))
[void]$Table.Rows.Add(
$CurrentWindowsVersion.Version,
$CurrentWindowsVersion.'Windows Edition',
$CurrentWindowsVersion.'OS Build',
$CurrentPatch.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - '),
"KB" + $CurrentPatch.href.Split('/')[-1],
"https://support.microsoft.com" + $CurrentPatch.href,
$LatestAvailablePatch.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - '),
"KB" + $LatestAvailablePatch.href.Split('/')[-1],
"https://support.microsoft.com" + $LatestAvailablePatch.href
)
Return $Table

미리 보기 및 대역 외 업데이트 제외하기

현재 설치된 업데이트보다 최신 버전의 미리 보기(Preview) 또는 대역 외(Out-of-band) 업데이트가 '최신 사용 가능 업데이트'로 표시되지 않도록 제외하고 싶다면, 아래 명령어를 실행하여 누적 업데이트에만 집중할 수 있습니다.

Get-CurrentPatchInfo -ExcludePreview -ExcludeOutofBand

배포된 전체 업데이트 목록 조회하기

다음 명령어를 사용하면 Microsoft가 현재 OS 버전에 대해 배포한 모든 Windows 업데이트 목록을 확인할 수 있습니다.

Get-CurrentPatchInfo -ListAvailable

전체 업데이트 목록에서 미리 보기 및 대역 외 업데이트만 제외하고 싶다면 아래 명령어를 실행하세요.

Get-CurrentPatchInfo -ListAvailable -ExcludePreview -ExcludeOutofBand

이것으로 끝입니다!

함께 읽으면 좋은 글: PowerShell Module Browser 사이트에서 cmdlet과 패키지를 검색해 보세요.