Skip to content

Docs never state how #Requires and comment-based help should be ordered in a script (about_Requires / about_Comments / about_Comment_Based_Help) #13414

Backlog

Description

@MatthewCKelly

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in Get-Foo cmdlet" instead of "Typo."
  • Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.

Links

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-7.6#rules-for-use
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comments?view=powershell-7.6#comment-based-help
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comments?view=powershell-7.6#requires
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-7.6#syntax-for-comment-based-help-in-scripts

Summary

None of the pages that describe #Requires or comment-based help say whether a #Requires statement should come before or after a script's comment-based help block, or whether the two interact at all. The pages only say #Requires can appear on any line, and separately say script help may be preceded only by comments and blank lines. They never connect the two, and no example shows a script that has both. Readers (and team style guides) are left to infer an order the documentation does not specify.

Details

What the pages say today (PowerShell 7.6 docs):

about_Requires, "Rules for use":

The #Requires statements can appear on any line in a script.

about_Comments, "#Requires":

#Requires can appear on any line in a script, but is processed in the same manner regardless of position.

about_Comment_Based_Help, "Syntax for comment-based help in scripts":

At the beginning of the script file. Script help can be preceded in the script only by comments and blank lines.

If the first item in the script body (after the help) is a function declaration, there must be at least two blank lines between the end of the script help and the function declaration.

about_Comment_Based_Help, "Syntax for comment-based help":

If a comment-based help topic follows a comment that's not part of the help topic, there must be at least one blank line between the last non-help comment line and the beginning of the comment-based help.

What is left unanswered:

  1. Is a script that starts with #Requires ... followed by the help block valid, or must the help block come first? "Can be preceded ... only by comments and blank lines" does not say whether a #Requires line counts as a comment for this rule.
  2. Is a script with the help block first and #Requires after it (before param()) equally valid? "Any line" suggests yes, but the two topics never say so together.
  3. Does a #Requires line placed directly above <# count as a "non-help comment" needing a blank line before the help block?
  4. Does a #Requires line between the help block and a function declaration or param() block count towards the "at least two blank lines" spacing rule?
  5. For a signed script, where help is advised to be at the beginning of the file, does that advice change the ordering?

Each of these pages is correct on its own, but a reader who needs both features in one script cannot tell from the documentation which ordering is supported, so unwritten rules (such as "#Requires must go after the help") get passed around as if they were documented.

No page currently contains an example script with both a #Requires statement and a comment-based help block.

Suggested Fix

  • Add a short note to the scripts section of about_Comment_Based_Help stating explicitly whether #Requires may appear before the help block, and whether it counts as a "comment" for the "preceded only by comments and blank lines" rule.
  • Add a matching sentence to "Rules for use" in about_Requires (and the #Requires section of about_Comments), linking to the comment-based help guidance.
  • Add one example script showing a #Requires statement and a comment-based help block together, with the blank-line spacing the help parser expects before param() or the first function declaration.
  • Cross-link about_Requires and about_Comment_Based_Help so each points to the other.

Activity

  1. added
    issue-doc-bug
    needs-triage
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue-doc-bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions