gpt4 book ai didi

powershell - 如何在 powershell 函数中自定义示例的标题

转载 作者:行者123 更新时间:2023-12-04 00:05:27 24 4
gpt4 key购买 nike

考虑以下 Powershell 命令:

Get-Help Get-Help -examples

当我执行它时,示例如下所示:
----- Example 1: Display basic information about a command -----

Get-Help Format-Table
Get-Help -Name Format-Table
Format-Table -?

These commands display basic information about the `Format-Table` cmdlet.

`Get-Help <name>` is the simplest and default syntax of `Get-Help` cmdlet. You can omit the parameter name ( Name ).

`<command-name> -?` works only for commands.

当我用 .EXAMPLE 标记 Powershell 方法时,如下所示:
<#
.SYNOPSIS
Does stuff

.DESCRIPTION
Details about doing stuff

.PARAMETER Foo
Foos things

.EXAMPLE
Invoke-FooBar -Foo bar, baz
Foos the bar and baz
#>

它给了我一个这样的例子:
-------------------------- EXAMPLE 1 --------------------------

PS C:\>Invoke-FooBar -Foo bar, baz

Foos the bar and baz

我的问题是,如何更改标题以描述我正在演示的内容?

最佳答案

你不能 - 从基于注释的帮助中提取的示例由内部 HelpCommentsParser 转换为 XML ,它使用以下语句为每个示例构造标题字符串:

string titleStr = string.Format(CultureInfo.InvariantCulture,
"\t\t\t\t-------------------------- {0} {1} --------------------------",
HelpDisplayStrings.ExampleUpperCase, count++);

relevant resource file包含单词 EXAMPLEHelpDisplayStrings.ExampleUpper值,这就是为什么它总是显示为 EXAMPLE 1 , EXAMPLE 2等等。

上面链接的代码来自 PowerShell Core 6,但基于注释的帮助工具自 3.0 版以来没有发生任何重大变化

关于powershell - 如何在 powershell 函数中自定义示例的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51656773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com