Powershell更新失败

27
当我在PowerShell中运行Update-Help时失败了。 我没有使用代理,而是使用了直接访问。 我也以管理员身份运行PowerShell。 不确定还要检查什么... 欢迎任何建议。
这是我的版本。
$PSVersionTable

Name                           Value                                                                                                                                           
----                           -----                                                                                                                                           
PSVersion                      5.1.14393.187                                                                                                                                   
PSEdition                      Desktop                                                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                         
BuildVersion                   10.0.14393.187                                                                                                                                  
CLRVersion                     4.0.30319.42000                                                                                                                                 
WSManStackVersion              3.0                                                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                                                             
SerializationVersion           1.1.0.1   

这里是错误:

PS C:\Windows> Update-Help
Update-Help : Failed to update Help for the module(s) : 
'AppBackgroundTask, AppLocker, AppvClient, Appx, AssignedAccess, BitLocker, BitsTransfer, BranchCache, CimCmdlets, ConfigCI, Defender, DirectAccessClientComponents, Dism, 
DnsClient, EventTracingManagement, International, iSCSI, ISE, Kds, Microsoft.PowerShell.Archive, Microsoft.PowerShell.Core, Microsoft.PowerShell.Diagnostics, 
Microsoft.PowerShell.Host, Microsoft.PowerShell.LocalAccounts, Microsoft.PowerShell.Management, Microsoft.PowerShell.ODataUtils, Microsoft.PowerShell.Security, 
Microsoft.PowerShell.Utility, Microsoft.WSMan.Management, MMAgent, MsDtc, MSMQ, NetAdapter, NetConnection, NetEventPacketCapture, NetLbfo, NetNat, NetQos, NetSecurity, 
NetSwitchTeam, NetTCPIP, NetworkConnectivityStatus, NetworkSwitchManager, NetworkTransition, PackageManagement, PcsvDevice, PKI, PnpDevice, PowerShellGet, PrintManagement, 
PSDesiredStateConfiguration, PSReadline, PSScheduledJob, PSWorkflow, PSWorkflowUtility, ScheduledTasks, SmbShare, SmbWitness, StartLayout, Storage, TLS, TroubleshootingPack, 
TrustedPlatformModule, UEV, VpnClient, Wdac, WindowsDeveloperLicense, WindowsErrorReporting, WindowsSearch, WindowsUpdate'
Access is denied. The command could not update Help topics for the Windows PowerShell core modules, or for any modules in the $pshome\Modules directory. To update these Help 
topics, start Windows PowerShell by using the "Run as Administrator" command, and try running Update-Help again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UpdatableHelpSystemRequiresElevation,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'Microsoft.PowerShell.Operation.Validation' with UI culture(s) {en-US} : The value of the HelpInfoUri key in the module 
manifest must resolve to a container or root URL on a website where the help files are stored. The HelpInfoUri 'https://www.msn.com/?ocid=NEFLS000' does not resolve to a 
container.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : InvalidHelpInfoUri,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'SecureBoot' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US. Make sure the 
HelpInfoUri property in the module manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

我重新运行了Update-Help。我认为它更新了大部分内容,但仍然出现以下错误。

Update-Help : Failed to update Help for the module(s) 'Microsoft.PowerShell.Operation.Validation' with UI culture(s) {en-US} : The value of the HelpInfoUri 
key in the module manifest must resolve to a container or root URL on a website where the help files are stored. The HelpInfoUri 
'https://www.msn.com/?ocid=NEFLS000' does not resolve to a container.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : InvalidHelpInfoUri,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'AppvClient' with UI culture(s) {en-US} : Help content cannot be found. Make sure the server is 
available and the help content location is properly defined in the HelpInfo XML.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : HelpContentNotFound,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'SecureBoot' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US. 
Make sure the HelpInfoUri property in the module manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

你看到的结果是True吗?([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator") - Matt
我收到了这个错误信息:在第1行第100个字符处
  • ... Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole‌​( [Secur ...
  • ~~
表达式或语句中出现意外的标记 '‌​'。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
- It's Just a Printer Driver
1
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole] "Administrator") 或者从 http://serverfault.com/a/97599/234050 查找相同的内容。第一个命令中有一些隐藏字符,是我在 e( 之间粘贴时出现的。 - Matt
@Matt,那些在e(之间的隐藏字符又出现了;也许是SO的一个bug?我已经注意到类似的问题不止一次了... U+200C 零宽度非连接符U+200B _零宽度空格_。 - JosefZ
它返回了true。 - It's Just a Printer Driver
显示剩余4条评论
3个回答

49

TL;DR 和解决方法

多年后,这仍然是大多数用户的问题。我想在这里进行彻底的解释。

两个问题:

  • Update-Help 需要以管理员身份运行 PowerShell
  • 微软已经破坏了更新链接,在每个系统上都会抛出错误。直到今天,你所提到的某些模块仍然会抛出错误

你的第一个错误是明显且直接的,这个输出直接包含在你的第一个错误输出中:

Access is denied. The command could not update Help topics for the Windows PowerShell core modules, or for any modules in the $pshome\Modules directory. To update these Help 
topics, start Windows PowerShell by using the "Run as Administrator" command, and try running Update-Help again.

为了{{抑制}}错误,但仍然下载所有可以下载的内容,您可以运行以下命令(在通过{{以管理员身份运行}}启动的PowerShell控制台中):
Update-Help -Verbose -Force -ErrorAction SilentlyContinue

或者

Update-Help -Verbose -Force -ErrorAction SilentlyContinue -ErrorVariable UpdateErrors

修复PSReadLine

编辑(2021年9月1日): 如果您想要修复PSReadLine模块,则可以使用特定的指令:

C:\Program Files\WindowsPowerShell\Modules\PSReadline重命名为C:\Program Files\WindowsPowerShell\Modules\PSReadLine(因为它是区分大小写的,所以我们需要PSReadLine而不是PSReadline)。

但可能还需要其他步骤。以下是其中一篇博客文章的完整演示:

  • 关闭所有powershell.exe进程。然后将PSReadline模块文件夹名称更改为PSReadLine
  • 以管理员权限打开powershell.exe会话。
  • 运行Remove-Module PSReadLine以删除自动加载的PSReadLine模块。
  • 运行Import-Module PSReadLine(使用大写的L)。
  • 然后运行Update-Help -Module PSReadLine -Force

参考PSReadLine更新修复的博客文章:

解决方法的说明

这是对Update-Help -Verbose -Force -ErrorAction SilentlyContinue -ErrorVariable UpdateErrors的解释,它的工作原理以及为什么需要执行,直到微软针对特定模块或Update-Help本身进行修复。

Update-Help的帮助文档中得知, 这就是需要管理员权限的原因:

Update-Help需要管理员权限。

您必须是计算机上Administrators组的成员,才能更新PowerShell Core模块的帮助文件。

要下载或更新$PSHOME\Modules目录中的PowerShell安装目录中的模块的帮助文件(包括PowerShell Core模块),请使用“以管理员身份运行”选项启动PowerShell。例如:Start-Process powershell.exe -Verb RunAs。

您还可以通过在Windows PowerShell集成脚本环境(ISE)的帮助菜单中使用“更新Windows PowerShell帮助”菜单项来更新帮助文件。

更新Windows PowerShell Help菜单项运行一个没有参数的Update-Help cmdlet。要更新$PSHOME目录中的模块的帮助,请使用“以管理员身份运行”选项启动Windows PowerShell ISE。

至于使用的参数:

表示此 cmdlet 不遵循每天一次的限制,跳过版本检查,并下载超过 1 GB 限制的文件。

如果没有此参数,Update-Help 每 24 小时运行一次。每个模块的下载内容限制为每个未压缩内容 1 GB,只有当帮助文件新于计算机上的现有文件时才安装帮助文件。

每天一次的限制保护托管帮助文件的服务器,并使您能够将 Update-Help 命令添加到 PowerShell 配置文件中,而不会产生重复连接或下载的资源成本。

  • -Verbose 表示提供黄色文本墙,描述正在尝试更新的模块、正在解析的 URI 等等。
  • -ErrorVariable UpdateErrors 将错误保存到变量中,可以通过 $UpdateErrors 变量检索错误
  • -ErrorAction SilentlyContinue 表示简单地忽略任何错误,并继续更新下一个可更新的模块

你可能会想为什么“禁止”错误被认为是一种修复。这是因为:

  • 如果您有一个运行此命令的脚本,并且不希望脚本因这些错误而退出。
  • 它仅抑制无法下载帮助的模块的错误,并仍然为所有其他模块下载帮助。
  • 如果仍然希望调查这些错误,则可以在$UpdateErrors变量中找到它们,并可以保存到文件或以其他方式处理。
  • 要真正解决抛出的错误,Microsoft必须采取措施修复自己的帮助文档端点。

等等,但这为什么是微软的问题?

以下是最新的Windows 10系统示例(截至2019年第四季度/2020年第一季度):

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.18362.145
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.145
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Get-WmiObject win32_operatingsystem | select Caption, Version

Caption                  Version
-------                  -------
Microsoft Windows 10 Pro 10.0.18363

对于那些在Windows上使用PowerShell的新手和经验丰富者来说,在更新帮助文档的第一步中看到这些Update-Help错误是一个很大的障碍和困惑。大多数错误并不是用户端的某种配置错误,但遗憾的是这已经成为默认和持续的命令输出期望了几年之久。
是的,解决方法可以解决问题。但是,如果人们通过抑制错误输出并继续前进来运行内置命令,那么这是一个糟糕的客户体验(也许不是教给人们最佳实践,因为可能会发生其他错误?)。抑制错误是所有人剩下的唯一选择。即使是从2016年开始,这里是最受欢迎的答案: PowerShell (5)Update-Help throws error after installing Windows 10 Anniversary Update 请注意,与HelpInfoUri相关的更新错误的标记accepted答案(不应该是接受的答案)在这里说:
“我认为你需要联系MS支持。” “问题出在你的机器和它的安装上,你需要得到支持来帮助你。我认为我们唯一能提供的建议就是重新安装Windows。(!!)
疯狂的事情!如果出现此错误,请勿重新安装!希望用户没有因为HelpInfoUri错误而进行重新安装。正如SamB此GitHub问题中直接专注于解决这个持续的问题中所说,Microsoft在其PowerShell清单文件中设置的HelpInfoURI值有误。在这台计算机上,WindowsUpdateProvider的模块清单没有给出任何归属,只指定了一个HelpInfoUrihttps://go.microsoft.com/fwlink/?linkid=390794,因此没有必要在弄清楚模块来自哪里并以某种方式证明这需要发布WindowsUpdateProvider补丁的情况下--只需要将该重定向指向适当的位置即可。如果在出现这些Update-Help错误的系统上运行以下内容,则应该看到输出:
Import-Module WindowsUpdateProvider
Get-Module WindowsUpdateProvider | select HelpInfoURI,Version                                                                                                                                                                                      

HelpInfoUri                                    Version
-----------                                    -------
https://go.microsoft.com/fwlink/?linkid=390794 1.0.0.2

WindowsUpdateProvider的源模块清单为例,位于此处:

C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\WindowsUpdateProvider\WindowsUpdateProvider.psd1

微软可以将链接重定向到一个可用的HelpInfoUri,这意味着客户端不需要进行任何更改。

顺便提一下,经常使用-ErrorAction SilentlyContinue的人可能会错过其他几个模块的帮助信息。截至今天,在标准的Windows 10桌面上,以下模块的帮助信息已损坏:

$TestModules = @("Microsoft.PowerShell.ODataUtils", "Microsoft.PowerShell.Operation.Validation", "UEV", "Whea", "WindowsDeveloperLicense", "defender", "configdefender",  "appvclient")
Import-Module $TestModules
$BorkedHelp = Get-Module $TestModules | select Name, Version, HelpInfoUri
$BorkedHelp

Name                                      Version   HelpInfoUri
----                                      -------   -----------
appvclient                                1.0.0.0   https://go.microsoft.com/fwlink/?LinkId=403112
configdefender                            1.0       https://go.microsoft.com/fwlink/?linkid=390762
defender                                  1.0       https://go.microsoft.com/fwlink/?linkid=390762
Microsoft.PowerShell.ODataUtils           1.0       https://go.microsoft.com/fwlink/?LinkId=509916
Microsoft.PowerShell.Operation.Validation 1.0.1     https://go.microsoft.com/fwlink/?LinkId=808399
UEV                                       2.1.639.0 https://go.microsoft.com/fwlink/?LinkId=826061
Whea                                      2.0.0.0   https://go.microsoft.com/fwlink/?linkid=390848
WindowsDeveloperLicense                   1.0.0.0   https://go.microsoft.com/fwlink/?linkid=285578

foreach ($uri in $BorkedHelp.helpinfouri) {Invoke-WebRequest $uri}

欢迎来到红色海洋,出现了404 - 文件或目录未找到错误,所有端点都需要重定向。有些端点已经破损了好几年,而有些则破损时间可能较短。

微软应该可以通过其链接转发周围的任何工具来修复这些问题,除非他们更新模块清单以指向新的工作HelpInfoURI端点,这对所有用户来说都不太友好。

如果微软的问题是默认情况下没有可下载的文档,并且链接可能是自动生成的保留,以便以后下载文档时使用,那么他们至少应该有一个最基本的HelpInfoURI端点,而不是一个破损的端点。

帮助微软意识到问题

遇到此问题并发现此解释有用的用户应访问GitHub上的此问题: MicrosoftDocs/windows-powershell-docs: Update-Help fails for WindowsUpdateProvider

编辑(09/01/2021):上述问题已被关闭,微软不再使用UserVoice进行反馈(在关闭问题时提到为适当的地方)。看起来最好的选择是前往Microsoft Tech Community: PowerShell,因为Microsoft支持文档中关于UserVoice的通知:

注意:我们将在2021年的日历年内逐个产品地远离UserVoice反馈站点。我们将利用第一方解决方案来获取客户反馈意见。参考 如果任何有问题的PowerShell模块有公共存储库,那么这些存储库就是提出关于破损的Update-Help功能问题的合适位置。如果它是随Microsoft产品一起提供的PowerShell模块,则需要向产品本身提出问题报告。
另一种替代方法
对于任何已知的帮助文档端点破损的PowerShell模块,您还可以注释掉PowerShell清单中的HelpInfoURI值。Update-Help仅尝试为HelpInfoURI具有值的模块下载更新。这可能对了解是否由于端点问题(例如托管您自己的模块文档的HelpInfoURI)而出现了新错误很有帮助。

4
哇,这种程度的无能来自世界上最大的软件公司之一,如果不是“最大”的话,已经远远超出了理解范围。正如你几次所说,他们的文档网站经常被移动或完全关闭,这是多年来一直存在的问题,我就是无法理解...无论如何,非常感谢您提供了详尽全面的答案!您的回答应该被采纳。 - Kenny83
使用管理员权限执行任务对我很有帮助。 - Rohan Bari

28

解决方法:

Update-Help -Verbose -Force -ErrorAction SilentlyContinue 

-verbose参数将输出命令正在执行的内容, -force参数即使在脚本执行过程中出现错误也会强制完成脚本, -ErrorAction SilentlyContinue参数将执行类似于上述操作的内容。

简而言之,那些以前没有更新的模块仍然不会被更新。


3

Update-Help 最初失败了,但以管理员身份运行后成功了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接