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

Viewing 7 reply threads
  • Author
    Posts
    • #167914
      Participant
      Topics: 13
      Replies: 58
      Points: 268
      Rank: Contributor

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

      help <name of the function> 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 <name of the function> it is listed twice in the drop down menu. Any suggestions on this?

    • #167917
      Participant
      Topics: 2
      Replies: 1752
      Points: 3,620
      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: 406
      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: 2
      Replies: 1752
      Points: 3,620
      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: 406
      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: 13
      Replies: 58
      Points: 268
      Rank: Contributor

      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: 1160
      Points: 4,056
      Helping Hand
      Rank: Community Hero

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

    • #167983
      Participant
      Topics: 2
      Replies: 1752
      Points: 3,620
      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. 😉 😀

Viewing 7 reply threads
  • The topic ‘help does not work in the function’ is closed to new replies.