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

标签 powershell

考虑以下 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/

相关文章:

powershell - 如何区分未设置参数与 $false、0、空字符串?

c# - 定义自定义 Powershell 对象

powershell - 在计算属性上设置宽度对输出没有影响

python - Powershell Python : Change version used

c# - 在 Visual Studio 中运行 PowerShell 脚本时无法获取 Active Directory 终端服务属性

c# - 从 C# 运行 Powershell

powershell - 如何更改 PowerShell Cmdlet 的默认确认选项?

c# - 代码在 c# dll 和 powershell 中表现不同

powershell - 如何检查是否安装了 PowerShell 模块?

powershell - PowerShell 中的函数返回值