PowerShell 3.0更新了许多新功能,尤其在Advanced Function中也有一些新特新改进,我们会接下来分篇幅分别讲解一下这些新特新。
今天我们要说的就是新增的CmdletBinding的HelpURI属性。HelpURI属性可以为你的方法,脚本函数指定一个在线版本的帮助文档,所有指定的链接方式都必须用http和https开头。
Function New-PowerShell
{
[CmdletBinding(HelpURI='http://www.microsoft.com')]
Param
(
[Parameter()]
$StringData
)
Write-Host $StringData
}
Get-Help New-PowerShell -Online
当你,使用参数Online参数时候就会自动链接打开'http://www.microsoft.com'链接。
这里要提到一点就是,相信大家一定记得在Comment-Based Help中,有一个".LINK" 节点,它在PowerShell文档中的作用也是起到帮助链接的作用,那么如果我此时开始HelpURI后,又同时设定Comment-Based Help,到底是哪个优先呢?
Function New-PowerShell
{
<#
.SYNOPSIS
test new feature in PowerShell 3.0
.EXAMPLE
New-PowerShell
.LINK
http://www.baidu.com
#>
[CmdletBinding(HelpURI='http://www.microsoft.com')]
Param
(
[Parameter()]
$StringData
)
Write-Host $StringData
}
Get-Help New-PowerShell -Online
大家在测试后,一定会发现,如上示例会自动跳转到http://www.baidu.com,也就是Comment-Based Help的优先级优于HelpURI。