Sha*_*aun 19 powershell powershell-2.0
我正在尝试使用Get-Help cmdlet以相同的格式显示基于注释的帮助,在该格式中,它显示从XML文件生成的cmdlet帮助主题.在TechNet 上的about_Comment_based_Help中记录了执行此操作的能力,但是当我针对我的脚本执行get-help cmdlet时,我只返回返回的脚本名称.任何帮助,将不胜感激!
PS C:\Admin> Get-Help .\checksystem.ps1 -full
checksystem.ps1
Run Code Online (Sandbox Code Playgroud)
checksystem.ps1脚本:
function IsAlive {
<#
.DESCRIPTION
Checks to see whether a computer is pingable or not.
.PARAMETER computername
Specifies the computername.
.EXAMPLE
IsAlive -computername testwks01
.NOTES
This is just an example function.
#>
param (
$computername
)
Test-Connection -count 1 -ComputerName $computername -TimeToLive 5 |
Where-Object { $_.StatusCode -eq 0 } |
Select-Object -ExpandProperty Address
}
IsAlive -computername 192.168.1.1
Run Code Online (Sandbox Code Playgroud)
And*_*der 18
它会工作,但你正试图在脚本上运行获取帮助.您已将帮助添加到该功能.如果您点源脚本,然后键入get-help isalive,您将看到该函数的帮助.
. .\checksystem.ps1 ; get-help isalive -full
Run Code Online (Sandbox Code Playgroud)
Jos*_*osh 12
它有效,你只需要确保你有正确的标题.我总是把评论块放在函数的正上方.我不确定它是否应该在函数内部工作.
下面是我的一个具有工作doc帮助的函数的示例.
##############################################################################
#.SYNOPSIS
# Gets a COM object from the running object table (ROT) similar to GetObject
# in Visual Basic.
#
#.DESCRIPTION
# To maintain consistency with New-Object this cmdlet requires the -ComObject
# parameter to be provided and the TypeName parameter is not supported.
#
#.PARAMETER TypeName
# Not supported, but provided to maintain consistency with New-Object.
#
#.PARAMETER ComObject
# The ProgID of a registered COM object, such as MapPoint.Application.
#
#.PARAMETER Force
# If an existing object is not found, instead of writing an error, a new
# instance of the object will be created and returned.
#
#.EXAMPLE
# $olMailItem = 0
# Get-Object -ComObject Outlook.Application | %{$_.CreateItem($olMailItem).Display()}
##############################################################################
function Get-Object {
[CmdletBinding(DefaultParameterSetName='Net')]
param (
[Parameter(ParameterSetName='Net', Position=1, Mandatory=$true)]
[String]$TypeName,
[Parameter(ParameterSetName='Com', Mandatory=$true)]
[String]$ComObject,
[Parameter()]
[Switch]$Force
)
if ( $TypeName ) { throw '-TypeName is not supported. Use -ComObject instead.' }
if ( $ComObject ) {
try {
[System.Runtime.InteropServices.Marshal]::GetActiveObject($ComObject)
}
catch [System.Management.Automation.MethodInvocationException] {
if ( $Force ) { New-Object -ComObject $ComObject }
else { Write-Error "An active object of type $ComObject is not available." }
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22589 次 |
| 最近记录: |