共用方式為


WSUS 和 Microsoft 更新目錄

適用於:Windows Server 2025、Windows Server 2022、Windows Server 2019、Windows Server 2016、Windows Server 2012 R2、Windows Server 2012

Microsoft更新類別目錄是一項服務,提供可透過公司網路散發的更新清單。 您可以使用目錄來尋找Microsoft軟體更新、驅動程式和 Hotfix 的相關信息。 WSUS currently includes an option to Import Updates from the Microsoft Update Catalog. However, the Import Updates action in WSUS was built using ActiveX, which is now deprecated. WSUS 內的這個匯入功能已取代為 PowerShell 腳本。 腳本可讓您將單一更新或多個更新匯入 WSUS。 本文提供目錄、匯入腳本,以及如何使用腳本的相關信息。

將更新匯入 WSUS 的必要條件

需要下列必要條件,才能使用PowerShell腳本將更新匯入 WSUS:

  • 任何已安裝 WSUS 管理控制台的電腦,不論其是否為 WSUS 伺服器,都可以用來匯入更新。
    • 從 WSUS 伺服器匯入時,請使用屬於 WSUS Administrators 群組或本機系統管理員群組成員的帳戶。
    • 從遠端電腦匯入時,請使用屬於 WSUS Administrators 群組成員的帳戶,並在本機電腦上具有系統管理許可權。 遠端電腦必須能夠透過網路連線到 WSUS 伺服器。

Microsoft更新目錄

Microsoft更新類別目錄可讓您搜尋各種更新欄位和類別。 這些更新欄位包括:

  • Update title
  • Description
  • Applicable products
  • Classifications
  • 知識庫文章編號以KB1234567形式呈現

搜尋硬體更新或驅動程式時,您也可以搜尋下列欄位:

  • Driver model
  • Manufacturer
  • Class
  • 四部分的硬體識別碼,例如 PCI\VEN_14E4&DEV_1677&SUBSYS_01AD1028

您可以藉由新增其他搜尋字詞來縮小搜尋範圍。 若要搜尋特定字串,請使用雙引號。

Note

目錄也可讓您使用 [下載] 按鈕直接從網站下載更新。 不過,以這種方式下載的更新的格式為 .MSU 。 WSUS 無法匯入格式的 .MSU 更新。 Windows Update 獨立安裝程式DISM 或其他更新工具通常會使用此文件類型。 某些工具會要求您先從 .MSU 擷取檔案,才能使用它們。

使用 PowerShell 將更新匯入 WSUS

使用下列指示將更新匯入 WSUS:

  1. 將文章中的 PowerShell 腳本匯入更新至 WSUS 複製到文字編輯器中,然後將其儲存為 ImportUpdateToWSUS.ps1。 使用您可以輕鬆地存取的位置,例如 C:\temp

  2. 在瀏覽器開啟Microsoft更新目錄 https://catalog.update.microsoft.com

  3. 搜尋您要匯入 WSUS 的更新。

  4. 從傳回的清單中,選取您要匯入 WSUS 的更新。 更新詳細資訊頁面將開啟。

  5. Use the Copy button on the update details page to copy the UpdateID.

  6. 腳本可用來匯入單一更新或多個更新。

    • 若要將多個更新匯入 WSUS,請貼上您要匯入文字檔之每個更新的 update 識別符。 列出每行一個更新標識碼,然後在完成時儲存文本檔。 使用您可以輕鬆地存取的位置,例如 C:\temp\UpdateIDs.txt
    • 若要匯入單一更新,您只需要複製單一 updateID。
  7. To import updates, open a PowerShell console as an administrator and run the script with the following syntax using any needed parameters:

    C:\temp\ImportUpdateToWSUS.ps1 [-WsusServer] <String> [-PortNumber] <Int32> [-UseSsl] [-UpdateId] <String> [-UpdateIdFilePath] <string> [<CommonParameters>]
    

    Example 1: While signed into a WSUS server that uses the default port, import a single update using the following syntax:

    .\ImportUpdateToWSUS.ps1 -UpdateId 12345678-90ab-cdef-1234-567890abcdef
    

    Example 2: Using a remote computer, import multiple updates into a WSUS server using SSL with the following syntax:

    .\ImportUpdateToWSUS.ps1 -WsusServer WSUSServer.contoso.com -PortNumber 8531 -UseSsl -UpdateIdFilePath C:\temp\UpdateIDs.txt
    
  8. The update files for updates that are imported are downloaded based on your Update files settings. 例如,如果您使用選項僅在更新核准時將更新檔案下載到此伺服器,則更新檔案會在核准更新時下載。 如需儲存更新選項的詳細資訊,請參閱 1.3 選擇 WSUS 儲存策略一節。

將更新匯入 WSUS 的 PowerShell 腳本

<#
.SYNOPSIS
Powershell script to import an update, or multiple updates into WSUS based on the UpdateID from the catalog.

.DESCRIPTION
This script takes user input and attempts to connect to the WSUS server.
Then it tries to import the update using the provided UpdateID from the catalog.

.INPUTS
The script takes WSUS server Name/IP, WSUS server port, SSL configuration option and UpdateID as input. UpdateID can be viewed and copied from the update details page for any update in the catalog, https://catalog.update.microsoft.com. 

.OUTPUTS
Writes logging information to standard output.

.EXAMPLE
# Use with remote server IP, port and SSL
.\ImportUpdateToWSUS.ps1 -WsusServer 127.0.0.1 -PortNumber 8531 -UseSsl -UpdateId 12345678-90ab-cdef-1234-567890abcdef

.EXAMPLE
# Use with remote server Name, port and SSL
.\ImportUpdateToWSUS.ps1 -WsusServer WSUSServer1.us.contoso.com -PortNumber 8531 -UseSsl -UpdateId 12345678-90ab-cdef-1234-567890abcdef

.EXAMPLE
# Use with remote server IP, defaultport and no SSL
.\ImportUpdateToWSUS.ps1 -WsusServer 127.0.0.1  -UpdateId 12345678-90ab-cdef-1234-567890abcdef

.EXAMPLE
# Use with localhost default port
.\ImportUpdateToWSUS.ps1 -UpdateId 12345678-90ab-cdef-1234-567890abcdef

.EXAMPLE
# Use with localhost default port, file with updateID's
.\ImportUpdateToWSUS.ps1 -UpdateIdFilePath .\file.txt


.NOTES  
# On error, try enabling TLS: https://learn.microsoft.com/mem/configmgr/core/plan-design/security/enable-tls-1-2-client

# Sample registry add for the WSUS server from command line. Restarts the WSUSService and IIS after adding:
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /V SchUseStrongCrypto /T REG_DWORD /D 1

## Sample registry add for the WSUS server from PowerShell. Restarts WSUSService and IIS after adding:
$registryPath = "HKLM:\Software\Microsoft\.NETFramework\v4.0.30319"
$Name = "SchUseStrongCrypto"
$value = "1" 
if (!(Test-Path $registryPath)) {
    New-Item -Path $registryPath -Force | Out-Null
}
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -Force | Out-Null
Restart-Service WsusService, w3svc

# Update import logs/errors are under %ProgramFiles%\Update Services\LogFiles\SoftwareDistribution.log

#>

param(
    [Parameter(Mandatory = $false, HelpMessage = "Specifies the name of a WSUS server, if not specified connects to localhost")]
    # Specifies the name of a WSUS server, if not specified connects to localhost.
    [string]$WsusServer,

    [Parameter(Mandatory = $false, HelpMessage = "Specifies the port number to use to communicate with the upstream WSUS server, default is 8530")]
    # Specifies the port number to use to communicate with the upstream WSUS server, default is 8530.
    [ValidateSet("80", "443", "8530", "8531")]
    [int32]$PortNumber = 8530,

    [Parameter(Mandatory = $false, HelpMessage = "Specifies that the WSUS server should use Secure Sockets Layer (SSL) via HTTPS to communicate with an upstream server")]
    # Specifies that the WSUS server should use Secure Sockets Layer (SSL) via HTTPS to communicate with an upstream server.  
    [Switch]$UseSsl,

    [Parameter(Mandatory = $true, HelpMessage = "Specifies the update Id we should import to WSUS", ParameterSetName = "Single")]
    # Specifies the update Id we should import to WSUS
    [ValidateNotNullOrEmpty()]
    [String]$UpdateId,

    [Parameter(Mandatory = $true, HelpMessage = "Specifies path to a text file containing a list of update ID's on each line", ParameterSetName = "Multiple")]
    # Specifies path to a text file containing a list of update ID's on each line.
    [ValidateNotNullOrEmpty()]
    [String]$UpdateIdFilePath
)

Set-StrictMode -Version Latest

# set server options
$serverOptions = "Get-WsusServer"
if ($psBoundParameters.containsKey('WsusServer')) { $serverOptions += " -Name $WsusServer -PortNumber $PortNumber" }
if ($UseSsl) { $serverOptions += " -UseSsl" }

# empty updateID list
$updateList = @()

# get update id's
if ($UpdateIdFilePath) {
    if (Test-Path $UpdateIdFilePath) {
        foreach ($id in (Get-Content $UpdateIdFilePath)) {
            $updateList += $id.Trim()
        }
    }
    else {
        Write-Error "[$UpdateIdFilePath]: File not found"
		return
    }
}
else {
    $updateList = @($UpdateId)
}

# get WSUS server
Try {
    Write-Host "Attempting WSUS Connection using $serverOptions... " -NoNewline
    $server = invoke-expression $serverOptions
    Write-Host "Connection Successful"
}
Catch {
    Write-Error $_
    return
}

# empty file list
$FileList = @()

# call ImportUpdateFromCatalogSite on WSUS
foreach ($uid in $updateList) {
    Try {
        Write-Host "Attempting WSUS update import for Update ID: $uid... " -NoNewline
        $server.ImportUpdateFromCatalogSite($uid, $FileList)
        Write-Host "Import Successful"
    }
    Catch {
        Write-Error "Failed. $_"
    }
}

Script parameters

WsusServer: <string>
Specifies the name of a WSUS server. 如果未指定,腳本會連線到localhost。

  • Required: false
  • Default value: localhost

PortNumber: <Int32>
Specifies the port number to use to communicate with the upstream WSUS server.

  • Required: false
  • Default value: 8530
  • Allowed values: 80, 443, 8530, 8531

UseSsl: <switch>
Specifies if Secure Sockets Layer (SSL) via HTTPS should be used to communicate with the WSUS server. 如果此參數名稱存在參數測試 $true ,且使用 SSL 連接到 WSUS 伺服器,則為 ,否則為 false。 When using the USeSSL parameter, set the PortNumber to either 443 or 8531.

  • Required: false

UpdateId: <string>
Specifies the update ID you want to import to WSUS. 如果您要匯入單一更新,則需要此參數。 UpdateId can't be used with UpdateIdFilePath.

  • Required: true, when importing a single updateID specified as a script parameter

UpdateIdFilePath: <string>
Specifies the path to a text file containing a list of update IDs on each line. 如果您要匯入多個更新,則需要此參數。 UpdateIdFilePath can't be used with UpdateId.

  • Required: true, when using a text file to import multiple updates

CommonParameters:
Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see About CommonParameters

限制對 Hotfix 的存取

WSUS 系統管理員可能會考慮限制他們從 Microsoft 更新目錄下載的 Hotfix 存取權。 若要限制可用的 Hotfix,請完成下列步驟:

  1. 啟動 Internet Information Services (IIS) 管理員 控制台。
  2. Navigate to the Content node under WSUS Administration web site.
  3. On the Content Home pane, double-click in the Authentication option.
  4. Select Anonymous Authentication and select Disable in the Actions pane on the right.
  5. Select Windows Authentication and select Enable in the Actions pane on the right.
  6. 在 WSUS 管理控制台中,為需要 Hotfix 的電腦建立 WSUS 目標群組,並將其新增至群組。 如需計算機和群組的詳細資訊,請參閱本指南中的 管理 WSUS 用戶端電腦和 WSUS 計算機群組 ,以及設定 WSUS 部署指南中的 WSUS 計算機群組
  7. 下載 Hotfix 的檔案。
  8. 設定這些檔案的許可權,讓只有這些計算機的計算機帳戶可以讀取它們。 您也必須允許網路服務帳戶完整存取檔案。
  9. 核准在步驟 2 中建立之 WSUS 目標群組的 Hotfix。

Note

You can remove updates that are imported from the Microsoft Update Catalog that are set as either Not Approved or Declined, by running the WSUS Server cleanup Wizard. 您可以重新匯入先前已從 WSUS 系統移除的更新。

以不同語言匯入更新

目錄包含支援多種語言的更新。

Important

比對 WSUS 伺服器支援的語言與匯入更新所支持的語言。

如果 WSUS 伺服器不支援更新中包含的所有語言,則不會將更新部署至用戶端電腦。 如果支援多種語言的更新已下載至 WSUS 伺服器,但尚未部署到用戶端電腦,且系統管理員取消選取更新中包含的其中一種語言,則更新將不會部署到用戶端。

Troubleshooting

“。腳本的 NOTES 區段可用於針對執行腳本時可能發生的問題進行疑難解答。

  • 如果您收到錯誤,請嘗試啟用傳輸層安全性 (TLS) 1.2。 如需詳細資訊,請參閱 如何在用戶端上啟用 TLS 1.2

  • 您可以使用下列命令,將與強式密碼編譯相關的登錄值新增程序自動化。 新增登錄值之後,手動重新啟動 Windows Server Update Services 服務和 World Wide Web Publishing 服務。

    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /V SchUseStrongCrypto /T REG_DWORD /D 1
    
  • 執行此 PowerShell 腳本,將新增與使用強密碼編譯相關的登錄值程式自動化,並重新啟動 Windows Server Update Services 服務和 World Wide Web Publishing 服務:

    $registryPath = "HKLM:\Software\Microsoft\.NETFramework\v4.0.30319"
    $Name = "SchUseStrongCrypto"
    $value = "1"
    if (!(Test-Path $registryPath)) {
       New-Item -Path $registryPath -Force | Out-Null
    }
    New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -Force | Out-Null
    Restart-Service WsusService, w3svc
    
  • Activity and/or errors related to importing updates can be found in %ProgramFiles%\Update Services\LogFiles\SoftwareDistribution.log of the WSUS server where updates are being imported.