本主題說明放置函式批注型說明的位置,讓 Get-Help Cmdlet 將批注型說明主題與正確的函式產生關聯。
在何處放置函式 Comment-Based 說明
函式主體的開頭。
在函式主體的結尾。
在
Function關鍵詞之前。 當函式位於腳本或腳本模組中時,批注型說明的最後一行與Function關鍵詞之間不能有一個以上的空白行。 否則,Get-Help將說明與腳本產生關聯,而不是與函式產生關聯。
函式中說明放置的範例
下列範例顯示函式以批注為基礎的說明的三個放置選項。
函式主體開頭的說明
下列範例顯示函式主體開頭的批注型。
function MyProcess
{
<#
.DESCRIPTION
The MyProcess function gets the Windows PowerShell process.
#>
Get-Process powershell
}
函式主體結尾的說明
下列範例顯示以批注為基礎的函式主體結尾。
function MyFunction
{
Get-Process powershell
<#
.DESCRIPTION
The MyProcess function gets the Windows PowerShell process.
#>
}
函式關鍵詞之前的說明
下列範例會根據函式關鍵詞之前的行顯示批注。
<#
.DESCRIPTION
The MyProcess function gets the Windows PowerShell process.
#>
function MyFunction { Get-Process powershell}