powershell@update-help更新文档和离线文档安装@并行加速安装帮助文档更新@安装报错问题

powershell update-help

  • Update-Help (Microsoft.PowerShell.Core) - PowerShell | Microsoft Learn

  • 虽然powershell会为cmdlet或者用户自定义的powershell函数生成文档,但是基本上仅限于函数参数的类型和属性信息,对于参数的直观描述往往是缺乏的,而且无法生成,例如ls -path这里的-Path参数的帮助文档

    • -Path <System.String[]>
      Specifies a path to one or more locations. Wildcards are accepted. The default location is the current directory (`.`).
      Required? false
      Position? 0
      Default value Current directory
      Accept pipeline input? True (ByPropertyName, ByValue)
      Accept wildcard characters? true
    • 如果没有安装相应文档,那么中间的一段描述 Specifies a path to one or more locations. Wildcards are accepted. The default location is the current directory (.).就没有

  • 在powershell中直接使用update-help可能会失败,特别是非英文系统

  • 建议使用必要的参数来更新powershell的帮助文档,或者使用离线的方式更新或着安装文档,尤其是多台设备共享

为所有可用模块更新文档

  • 英文文档一定存在,所以报错机率比较小
  • 使用verbose参数来查看安装进度,及早发现问题
update-help -Verbose -UICulture en-US

为指定模块更新帮助文档

  • 比如我们为模块Microsoft.Powershell.Management更新文档

  • PS🌙[BAT:99%][MEM:63.5% (4.99/7.85)GB][1:10:04]
    # [cxxu@CXXUREDMIBOOK][<W:192.168.1.46>][~]
    PS> update-help -Module Microsoft.PowerShell.Management -Verbose
    VERBOSE: Resolving URI: "https://aka.ms/powershell73-help"
    VERBOSE: Your connection has been redirected to the following URI: "https://pshelpprod.blob.core.windows.net/cabinets/powershell-7.3/"
    VERBOSE: Postponing error and trying fallback cultures, will show as error if none of fallbacks are supported:
    The specified culture is not supported: zh-CN. Specify a culture from the following list: {en-US}.
    VERBOSE: Resolving URI: "https://aka.ms/powershell73-help"
    VERBOSE: Your connection has been redirected to the following URI:
    ....
    Update-Help: Failed to update Help for the module(s) 'Microsoft.PowerShell.Management' with UI culture(s) {zh-CN} : The specified culture is not supported: zh-CN. Specify a culture from the following list: {en-US}..
    English-US help content is available and can be installed using: Update-Help -UICulture en-US.
    PS🌙[BAT:99%][MEM:62.73% (4.92/7.85)GB][1:11:03]
    # [cxxu@CXXUREDMIBOOK][<W:192.168.1.46>][~]
    PS> update-help -UICulture en-US -Verbose -Module Microsoft.Powershell.Management
    VERBOSE: Resolving URI: "https://aka.ms/powershell73-help"
    VERBOSE: Your connection has been redirected to the following URI: "https://pshelpprod.blob.core.windows.net/cabinets/powershell-7.3/"
    VERBOSE: Performing the operation "Update-Help" on target "Microsoft.PowerShell.Management, Current Version: 0.0.0.0, Available Version: 7.3.0.0, UICulture: en-US".
    VERBOSE: Microsoft.PowerShell.Management: Updated C:\Users\cxxu\Documents\PowerShell\Help\en-US\Microsoft.PowerShell.Commands.Management.dll-Help.xml. Culture en-US Version 7.3.0.0

保存文档到本地(save-help)

Save-Help (Microsoft.PowerShell.Core) - PowerShell | Microsoft Learn

你需要指定一个存在的目录作为Save-Help的参数,否则无法保存

PS🌙[BAT:99%][MEM:53.45% (4.2/7.85)GB][1:30:55]
# [cxxu@CXXUREDMIBOOK][<W:192.168.1.46>][~\Desktop]
PS> Save-Help -Verbose -UICulture en-US -DestinationPath C:\Share\
VERBOSE: Resolving URI: "https://aka.ms/powershell73-help"
VERBOSE: Your connection has been redirected to the following URI: "https://pshelpprod.blob.core.windows.net/cabinets/powershell-7.3/"
VERBOSE: CimCmdlets: Saved C:\Share\CimCmdlets_fb6cc51d-c096-4b38-b78d-0fed6277096a_en-US_HelpContent.cab. Culture en-US Version 7.3.0.0
VERBOSE: Resolving URI: "https://aka.ms/powershell73-help"
VERBOSE: Your connection has been redirected to the following URI:
...
VERBOSE: Your connection has been redirected to the following URI: "https://pshelpprod.blob.core.windows.net/cabinets/powershell-7.3/"
VERBOSE: Microsoft.PowerShell.Core: Saved C:\Share\Microsoft.PowerShell.Core_00000000-0000-0000-0000-000000000000_en-US_HelpContent.cab. Culture en-US Version 7.3.0.0
PS🌙[BAT:99%][MEM:33.57% (2.64/7.85)GB][1:34:18]
# [cxxu@CXXUREDMIBOOK][<W:192.168.1.46>][~\Desktop]

安装了快5分钟才结束,总体积大约2~3MB

使用并行下载策略

$modules = Get-Module -ListAvailable | Where-Object -Property HelpInfoUri
$Destination = 'C:\PsHelpx' #指定你想要的下载目录即可
New-Item -ItemType Directory -Path $Destination -Verbose -Force
$modules.Name | ForEach-Object -Parallel {
# param($Destination)
$Destination = $using:Destination
#这里可以指定verbose观察输出,也可以不使用-Verbose详情,检查下载目录即可
Save-Help -Verbose -Module $_ -DestinationPath $Destination -UICulture en-us -ErrorAction SilentlyContinue
} -ThrottleLimit 64

耗时在10秒内

也可以用并发的方式在线安装

$modules = Get-Module -ListAvailable | Where-Object -Property HelpInfoUri
$modules.Name | ForEach-Object -Parallel {
#这里可以指定verbose观察输出,也可以不使用-Verbose详情,检查下载目录即可
update-help -Verbose -Module $_ -UICulture en-us # -ErrorAction SilentlyContinue
} -ThrottleLimit 64

分享给其他设备安装

  • 局域网内可以使用smb等工具分享,也可以配合robocopy传输内容给对方

  • 对方接受后执行update-help命令安装(注意仍然要指定-UICulture en-us),部分模块的文档会安装失败,这种情况下需要手动补充安装

posted @   xuchaoxin1375  阅读(36)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2023-09-26 EM@根式@分数指数幂
2023-09-26 AM@函数的基本概念
2022-09-26 sklearn_分类预测(KNN,GNB,...)示例(疾病简单二分类)
2021-09-26 web@浏览器浏览体验优化工具扩展@html5网页大纲生成工具@文档独立滚动大纲生成插件(headingsMap)@提取目录tableOfContent
2021-09-26 powershell@使用指南与入门命令
点击右上角即可分享
微信分享提示