help does not work in the function

Welcome Forums General PowerShell Q&A help does not work in the function

This topic contains 7 replies, has 4 voices, and was last updated by

 
Participant
1 month, 3 weeks ago.

  • Author
    Posts
  • #167914

    Participant
    Topics: 10
    Replies: 48
    Points: 198
    Rank: Participant

    I have created a function with the [cmdletbinding()] attribute, however when I run

    help it does not return the help on the function. However the function works fine when I run it with the specified parameters.

    and when I use help it is listed twice in the drop down menu. Any suggestions on this?

  • #167917

    Participant
    Topics: 1
    Replies: 1528
    Points: 2,581
    Helping Hand
    Rank: Community Hero

    Hmmm ... please be honest: Do you really think you provided enough information for us to be able to help you? 😉 😀 Please provide more detailed information.

  • #167923

    Participant
    Topics: 4
    Replies: 54
    Points: 382
    Helping Hand
    Rank: Contributor

    Write it like this and show us

     

    
    < #
    .Synopsis
    Short description
    .DESCRIPTION
    Long description
    .EXAMPLE
    Example of how to use this cmdlet
    .EXAMPLE
    Another example of how to use this cmdlet
    #>
    function Verb-Noun
    {
    [CmdletBinding()]
    [Alias()]
    [OutputType([int])]
    Param
    (
    # Param1 help description
    [Parameter(Mandatory=$true,
    ValueFromPipelineByPropertyName=$true,
    Position=0)]
    $Param1,
    
    # Param2 help description
    [int]
    $Param2
    )
    
    Begin
    {
    }
    Process
    {
    }
    End
    {
    }
    }
    
    
  • #167929

    Participant
    Topics: 1
    Replies: 1528
    Points: 2,581
    Helping Hand
    Rank: Community Hero

    Hmmm ... I recommend to read The PowerShell Best Practices and Style Guide – especially the chapter about Code Layout & Formatting and there particularily the paragraph about Indentation! 😉 😀

  • #167932

    Participant
    Topics: 4
    Replies: 54
    Points: 382
    Helping Hand
    Rank: Contributor

    Hmmm ... I recommend to read The PowerShell Best Practices and Style Guide – especially the chapter about Code Layout & Formatting and there particularily the paragraph about Indentation! 😉 😀

    thats the site 🙂

    my editor works like a charm 🙂

     

  • #167935

    Participant
    Topics: 10
    Replies: 48
    Points: 198
    Rank: Participant

    I fixed one part of the issue. I deleted the Module folder and recreated it. It is under Documents\WindowsPowerShell\Modules\Get-Test\Get-Test.psm1

    Now if I type help Get-Test, it shows the help. However still when I run help Get-T I see all the functions which start with Get-T and I see two listing for Get-Test, the first command works fine. However when I select the second Get-Test in the list, it types the below in the console.

    help Get-Test\Get-Test

    and when I run it, it returns an error saying Get-help: Get-help could not find Get-Test\Get-Test in a help file in this session.

  • #167956

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,438
    Helping Hand
    Rank: Community Hero

    Are you still using the PowerShell console session you opened before. Try opening a new console.

  • #167983

    Participant
    Topics: 1
    Replies: 1528
    Points: 2,581
    Helping Hand
    Rank: Community Hero

    thats the site ... my editor works like a charm

    OK, so how do you think others do it here in this forum? 😉 ... I'll show you what I mean:

    < #
            .SYNOPSIS
                A brief description of the function.
    
            .DESCRIPTION
                A detailed description of the function.
    
            .PARAMETER  ParameterA
                The description of the ParameterA parameter.
    
            .PARAMETER  ParameterB
                The description of the ParameterB parameter.
    
            .EXAMPLE
                PS C:\> Get-Something -ParameterA 'One value' -ParameterB 32
    
            .EXAMPLE
                PS C:\> Get-Something 'One value' 32
    
            .INPUTS
                System.String,System.Int32
    
            .OUTPUTS
                System.String
    
            .NOTES
                Additional information about the function go here.
    
            .LINK
                about_functions_advanced
    
            .LINK
                about_comment_based_help
    
        #>
    function Test-AdvancedFunction {
        [CmdletBinding()]
        [OutputType([System.Int32])]
        param(
            [Parameter(Position = 0, Mandatory = $true)]
            [ValidateNotNullOrEmpty()]
            [System.String]
            $Name,
    
            [Parameter(Position = 1)]
            [ValidateNotNull()]
            [System.Int32]
            $Index
        )
        Begin {
            try {
            
            }
            catch {
                throw
            }
        }
        Process {
            try {
            
            }
            catch {
                throw
            }
        }
        End {
            try {
            }
            catch {
                throw
            }
        }
    }

    I'd say: No, it's not the site. 😉 😀

You must be logged in to reply to this topic.