适用于:Windows Server 2025、Windows Server 2022、Windows Server 2019、Windows Server 2016、Windows Server 2012 R2、Windows Server 2012
Microsoft更新目录是一项服务,提供一系列可通过公司网络分发的更新。 可以使用目录查找有关Microsoft软件更新、驱动程序和修补程序的信息。 WSUS 当前包含从Microsoft更新目录 导入更新 的选项。 但是,WSUS 中的 导入更新 作是使用 ActiveX 生成的,现已弃用。 WSUS 中的此导入功能已替换为 PowerShell 脚本。 该脚本允许将单个更新或多个更新导入 WSUS。 本文提供有关目录、导入脚本以及如何使用脚本的信息。
将更新导入 WSUS 的先决条件
使用 PowerShell 脚本将更新导入 WSUS 需要满足以下先决条件:
- 安装了 WSUS 管理控制台的任何计算机,无论是否是 WSUS 服务器,都可用于导入更新。
- 从 WSUS 服务器导入时,请使用作为 WSUS 管理员组或本地管理员组成员的帐户。
- 从远程计算机导入时,请使用作为 WSUS 管理员组成员的帐户,并且对本地计算机具有管理权限。 远程计算机必须能够通过网络访问 WSUS 服务器。
Microsoft更新目录
Microsoft更新目录允许搜索各种更新字段和类别。 这些更新字段包括:
- 更新标题
- DESCRIPTION
- 适用的产品
- 分类
- 采用
KB1234567
格式的知识库文章编号
搜索硬件更新或驱动程序时,还可以搜索以下字段:
- 驱动程序模型
- 制造者
- 班级
- 四部分硬件 ID,例如
PCI\VEN_14E4&DEV_1677&SUBSYS_01AD1028
。
可以通过添加其他搜索词来缩小搜索范围。 若要搜索特定字符串,请使用双引号。
注释
目录还允许你使用下载按钮直接从站点下载更新。 但是,以这种方式下载的更新采用.MSU
格式。 WSUS 无法以 .MSU
格式导入更新。 Windows 更新独立安装程序、 DISM 或其他更新工具通常使用此文件类型。 某些工具要求先从 .MSU
文件中提取文件,然后才能使用这些文件。
使用 PowerShell 将更新导入 WSUS
使用以下说明将更新导入 WSUS:
从本文复制将更新导入 WSUS 的 PowerShell 脚本,并将其粘贴到文本编辑器,另存为
ImportUpdateToWSUS.ps1
。 使用可以轻松访问的位置,例如C:\temp
。在浏览器中打开Microsoft更新目录 https://catalog.update.microsoft.com。
查找您要导入到 WSUS 中的更新。
从返回的列表中,选择要导入到 WSUS 中的更新。 此时会打开更新详细信息页。
使用更新详细信息页上的 “复制 ”按钮复制 UpdateID。
该脚本可用于导入单个更新或多个更新。
- 若要将多个更新导入 WSUS,请将要导入的每个更新的 update ID 粘贴到文本文件中。 完成后,每行列出一个更新 ID,然后保存文本文件。 使用可以轻松访问的位置,例如
C:\temp\UpdateIDs.txt
。 - 若要导入单个更新,只需复制单个 updateID。
- 若要将多个更新导入 WSUS,请将要导入的每个更新的 update ID 粘贴到文本文件中。 完成后,每行列出一个更新 ID,然后保存文本文件。 使用可以轻松访问的位置,例如
若要导入更新,请以管理员身份打开 PowerShell 控制台,并使用任何所需的 参数使用以下语法运行脚本:
C:\temp\ImportUpdateToWSUS.ps1 [-WsusServer] <String> [-PortNumber] <Int32> [-UseSsl] [-UpdateId] <String> [-UpdateIdFilePath] <string> [<CommonParameters>]
示例 1:登录到使用默认端口的 WSUS 服务器时,使用以下语法导入单个更新:
.\ImportUpdateToWSUS.ps1 -UpdateId 12345678-90ab-cdef-1234-567890abcdef
示例 2:通过使用远程计算机和SSL,利用以下语法将多个更新导入到 WSUS 服务器:
.\ImportUpdateToWSUS.ps1 -WsusServer WSUSServer.contoso.com -PortNumber 8531 -UseSsl -UpdateIdFilePath C:\temp\UpdateIDs.txt
导入的更新的更新文件会根据你的更新文件设置进行下载。 例如,如果使用此选项仅在 更新获得批准时将更新文件下载到此服务器,则更新文件将在更新获得批准时下载。 有关存储更新的选项的详细信息,请参阅 第 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. $_"
}
}
脚本参数
WsusServer: <字符串>
指定 WSUS 服务器的名称。 如果未指定,脚本将连接到 localhost。
- 必需: false
- 默认值:localhost
PortNumber: <Int32>
指定要用于与上游 WSUS 服务器通信的端口号。
- 必需: false
- 默认值:8530
- 允许的值:80、443、8530、8531
UseSsl: <开关>
指定是否应使用安全套接字层(SSL)通过 HTTPS 与 WSUS 服务器通信。 如果此参数名称存在,则进行参数测试 $true
并通过 SSL 连接到 WSUS 服务器,否则使用 false
。 使用 USeSSL 参数时,将 PortNumber 设置为 443 或 8531。
- 必需: false
UpdateId: <字符串>
指定要导入到 WSUS 的更新 ID。 如果要导入单个更新,则需要此参数。
UpdateId 不能与 UpdateIdFilePath 一起使用。
- Required:true,导入指定为脚本参数的单个 updateID 时
UpdateIdFilePath: <字符串>
指定文本文件的路径,其中包含每行的更新 ID 列表。 如果要导入多个更新,则需要此参数。
UpdateIdFilePath 不能与 UpdateId 一起使用。
- 必需:true,使用文本文件导入多个更新时
CommonParameters:
Verbose、Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、OutBuffer、PipelineVariable、OutVariable。 有关详细信息,请参阅 CommonParameters
限制对修补程序的访问
WSUS 管理员可能会考虑限制对从Microsoft更新目录下载的修补程序的访问。 要限制可用的修补程序,请完成以下步骤:
- 启动 Internet Information Services (IIS) 管理器 控制台。
- 导航至 WSUS 管理网站下的内容节点。
- 在 “内容主页 ”窗格中,双击“ 身份验证 ”选项。
- 选择“匿名身份验证”,然后在右侧的“作”窗格中选择“禁用”。
- 选择Windows 身份验证,然后在右侧操作窗格中选择启用。
- 在 WSUS 管理控制台中,为需要修补程序的计算机创建 WSUS 目标组,并把这些计算机添加到该组中。 有关计算机和组的详细信息,请参阅本指南中的 “管理 WSUS 客户端计算机和 WSUS 计算机组 ”,并在 WSUS 部署指南中配置 WSUS 计算机组 。
- 下载修补程序文件。
- 设置这些文件的权限,以便只有这些计算机的计算机帐户才能读取它们。 还需要允许网络服务帐户完全访问文件。
- 批准步骤 2 中创建的 WSUS 目标组的修补程序。
注释
可以通过运行 WSUS 服务器清理向导,删除从设置为 “未批准 ”或 “已拒绝”的Microsoft更新目录导入的更新。 可以重新导入以前从 WSUS 系统中删除的更新。
以不同语言导入更新
该目录包含支持多种语言的更新。
重要
将 WSUS 服务器支持的语言与导入的更新支持的语言匹配。
如果 WSUS 服务器不支持更新中包含的所有语言,则不会将更新部署到客户端计算机。 如果支持多种语言的更新已下载到 WSUS 服务器,但尚未部署到客户端计算机,并且管理员取消选择更新中包含的其中一种语言,则不会将更新部署到客户端。
故障排除
“.脚本的“NOTES”部分可用于排查运行脚本时可能出现的问题。
如果收到错误,请尝试启用传输层安全性 (TLS) 1.2。 有关详细信息,请参阅 如何在客户端上启用 TLS 1.2
可以使用以下命令自动执行添加与使用强加密相关的注册表值的过程。 添加注册表值后,手动重启 Windows Server Update Services 服务和万维网发布服务。
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /V SchUseStrongCrypto /T REG_DWORD /D 1
运行此 PowerShell 脚本以自动添加与使用强加密相关的注册表值并重启 Windows Server Update Services 服务和万维网发布服务的过程:
$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
可以在导入更新的 WSUS 服务器的%ProgramFiles%\Update Services\LogFiles\SoftwareDistribution.log 中找到与导入更新相关的活动和/或错误。