begin { \# we do the adjustments only when the user has submitted \# the -Name, -Category, and -Online parameters if ( (@($PSBoundParameters.Keys) -ne'Name'-ne'Category'-ne'Online'). Count -eq0 ) { \# check whether there IS online help available at all \# retrieve the help URI $help = Microsoft.PowerShell.Core\Get-Command -Name $Name \# reset the parameter -Online based on availability of online help $PSBoundParameters['Online']= [string]::IsNullOrWhiteSpace($help.HelpUri) -eq $false }
\# once the parameter adjustment has been processed, call the original \# Get-Help cmdlet with the parameters found in $PSBoundParameters \# turn the original Get-Help cmdlet into a proxy command receiving the \# adjusted parameters \# with a proxy command, you can invoke its begin, process, and end \# logic separately. That's required to preserve pipeline functionality $cmd = Get-Command -Name 'Get-Help' -CommandType Cmdlet $proxy = {& $cmd @PSBoundParameters}. GetSteppablePipeline($myInvocation.CommandOrigin)
\# now, call its default begin, process, and end blocks in the appropriate \# script blocks so it integrates in real-time pipelines $proxy.Begin($PSCmdlet) }
process { $proxy.Process($_) }
end { $proxy.End() }
\# use the original help taken from Get-Help for this function <# .ForwardHelpTargetName Microsoft.PowerShell.Core\Get-Help .ForwardHelpCategory Cmdlet \#>}
begin { \# determine whether -Online should be made a default if ( \# user submitted -Name only ( $PSBoundParameters.Count -eq 1 -and $PSBoundParameters.ContainsKey('Name') ) -or \# system submitted -Name and -Category (when using -?) ( $PSBoundParameters.Count -eq2-and $PSBoundParameters.ContainsKey('Name') -and $PSBoundParameters.ContainsKey('Category') ) ) { \# prerequisites are OK, now check whether there IS online help \# available at all \# retrieve the help URI $help = Microsoft.PowerShell.Core\Get-Command -Name $Name \# set the -Online parameter only if there is a help URI $PSBoundParameters['Online']= [string]::IsNullOrWhiteSpace($help.HelpUri) -eq $false }
\# once the parameter adjustment has been processed, call the original \# Get-Help cmdlet with the parameters found in $PSBoundParameters \# turn the original Get-Help cmdlet into a proxy command receiving the \# adjusted parameters \# with a proxy command, you can invoke its begin, process, and end \# logic separately. That's required to preserve pipeline functionality $cmd = Get-Command -Name 'Get-Help' -CommandType Cmdlet $proxy = {& $cmd @PSBoundParameters}. GetSteppablePipeline($myInvocation.CommandOrigin)
\# now, call its default begin, process, and end blocks in the appropriate \# script blocks so it integrates in real-time pipelines $proxy.Begin($PSCmdlet) }
process { $proxy.Process($_) }
end { $proxy.End() }
\# use the original help taken from Get-Help for this function <# .ForwardHelpTargetName Microsoft.PowerShell.Core\Get-Help .ForwardHelpCategory Cmdlet \#>}