Microsoft更新目录是一项服务,提供一系列可通过公司网络分发的更新。 可以使用目录查找有关Microsoft软件更新、驱动程序和修补程序的信息。 WSUS 当前包含从Microsoft更新目录导入更新的选项。 但是,WSUS 中的 导入更新 作是使用 ActiveX 生成的,现已弃用。 WSUS 中的此导入功能已替换为 PowerShell 脚本。 该脚本允许将单个更新或多个更新导入 WSUS。 本文提供有关目录、导入脚本以及如何使用脚本的信息。
将更新导入 WSUS 的先决条件
使用 PowerShell 脚本将更新导入 WSUS 需要满足以下先决条件:
- 安装了 WSUS 管理控制台的任何计算机,无论是否是 WSUS 服务器,都可用于导入更新。
- 从 WSUS 服务器导入时,请使用作为 WSUS 管理员组或本地管理员组成员的帐户。
- 从远程计算机导入时,请使用作为 WSUS 管理员组成员的帐户,并且对本地计算机具有管理权限。 远程计算机必须能够通过网络访问 WSUS 服务器。
Microsoft更新目录
Microsoft更新目录允许搜索各种更新字段和类别。 这些更新字段包括:
- 更新标题
- Description
- 适用的产品
- Classifications
- 采用以下格式的知识库文章编号
KB1234567
搜索硬件更新或驱动程序时,还可以搜索以下字段:
- 驱动程序模型
- Manufacturer
- Class
- 四部分硬件 ID,例如
PCI\VEN_14E4&DEV_1677&SUBSYS_01AD1028。
可以通过添加其他搜索词来缩小搜索范围。 若要搜索特定字符串,请使用双引号。
Note
通过目录,还可以使用下载按钮直接从网站下载更新。 但是,以这种方式 .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 粘贴到文本文件中。 每行列出一个 updateID。 完成后保存文本文件。 使用可以轻松访问的位置,例如
C:\temp\UpdateIDs.txt。 - 若要导入单个更新,只需复制单个 updateID。
- 若要将多个更新导入 WSUS,请将要导入的每个更新的 update ID 粘贴到文本文件中。 每行列出一个 updateID。 完成后保存文本文件。 使用可以轻松访问的位置,例如
若要导入更新,请以管理员身份打开 PowerShell 控制台,并使用以下语法运行脚本,并使用任何所需的 参数:
C:\temp\ImportUpdateToWSUS.ps1 [-WsusServer] <String> [-PortNumber] <Int32> [-UseSsl] [-UpdateId] <String> [-UpdateIdFilePath] <string> [<CommonParameters>]示例 1:通过指定服务器名称和端口号将单个更新导入 WSUS 服务器:
.\ImportUpdateToWSUS.ps1 -WsusServer WSUSServer.contoso.com -PortNumber 8530 -UpdateId 12345678-90ab-cdef-1234-567890abcdef示例 2:使用远程计算机,使用以下语法将多个更新导入 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 by using the provided UpdateID from the catalog.
.INPUTS
The script takes WSUS server Name/IP, WSUS server port, SSL configuration option, and UpdateID as inputs. 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 updateIDs.
.\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 name isn't 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 to 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 the path to a text file containing update IDs 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 IDs.
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 一起使用。
- 必需:导入指定为脚本参数的单个 updateID 时为 true。
UpdateIdFilePath: <字符串>
指定包含每行更新 ID 的文本文件的路径。 如果要导入多个更新,则需要此参数。
UpdateIdFilePath 不能与 UpdateId 一起使用。
- 必需:使用文本文件导入多个更新时为 true。
CommonParameters:
Verbose、Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、OutBuffer、PipelineVariable 和 OutVariable。 有关详细信息,请参阅 about_CommonParameters。
限制对修补程序的访问
WSUS 管理员可能会考虑限制对从Microsoft更新目录下载的修补程序的访问。 若要限制可用的修补程序,请完成以下步骤:
- 启动 Internet Information Services (IIS) 管理器控制台。
- 转到 WSUS 管理网站下的内容节点。
- 在 “内容主页 ”窗格中,双击“ 身份验证 ”选项。
- 选择“匿名身份验证”,然后在右侧的“作”窗格中选择“禁用”。
- 选择 Windows 身份验证,然后在右侧的“作”窗格中选择“启用”。
- 在 WSUS 管理控制台中,为需要修补程序的计算机创建 WSUS 目标组,并把这些计算机添加到该组中。 有关计算机和组的详细信息,请参阅本指南中的 “管理 WSUS 客户端计算机和 WSUS 计算机组 ”,并在 WSUS 部署指南中配置 WSUS 计算机组 。
- 下载修补程序文件。
- 设置这些文件的权限,以便只有这些计算机的计算机帐户才能读取它们。 还需要允许网络服务帐户完全访问文件。
- 批准步骤 2 中创建的 WSUS 目标组的修补程序。
Note
可以通过运行 WSUS 服务器清理向导,删除从Microsoft更新目录导入的更新,这些更新设置为 “未批准 ”或 “拒绝 ”。 可以重新导入以前从 WSUS 系统中删除的更新。
以不同语言导入更新
该目录包含支持多种语言的更新。
Important
将 WSUS 服务器支持的语言与导入的更新支持的语言匹配。
如果 WSUS 服务器不支持更新中包含的所有语言,则不会将更新部署到客户端计算机。 如果支持多种语言的更新已下载到 WSUS 服务器,但尚未部署到客户端计算机,并且管理员取消选择更新中包含的其中一种语言,则不会将更新部署到客户端。
Troubleshooting
“.脚本的“备注”部分可用于排查运行脚本时可能发生的问题。
如果收到错误,请尝试启用传输层安全性 (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 中找到与导入更新相关的活动和/或错误。