# Comment-Based Help

**URL:** <https://forums.powershell.org/t/comment-based-help/18073>\
**Category:** PowerShell Help\
**Created:** [November 29, 2021, 11:38pm UTC](https://forums.powershell.org/t/comment-based-help/18073 "2021-11-29T23:38:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [November 29, 2021, 11:38pm UTC](https://forums.powershell.org/t/comment-based-help/18073/1 "2021-11-29T23:38:33Z")

</div>

Hi Everyone in this script when there is no space between the commend and \<#  
I do not get the full help section that I am looking for. But when I have a blank line in-between them the help section shows up properly. I took a look at this and in example two it seems related.

> **[Examples of Comment-Based Help - PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/developer/help/examples-of-comment-based-help?view=powershell-7.2)**
>
> Examples of Comment-Based Help

If someone could provide some input that would be great!  
Im trying understand has much has I can.

#This is a block comment  
\<#  
.Synopsis  
This script gets you the storage space on the localhost(your computer) or remote computer for the C: drive

.Description  
This will make things easier to grab storage information

.Parameter ComputerName  
This is for remote and local computer

.Example  
.\get\_freespace\_cdrive.ps1 -computername “Some name here”  
Shows how to do it on a remote computer

#\>  
#This turns on the ability to use parameter attributes , For here it will serve the purpose of making things mandatory  
[cmdletBinding()]

#paramitize so then script wont get edited  
param(  
#Line 12 ONLY EFFECTS THE NEXT parameter after it SO IT WONT EFFECT $BOGUS VARIABLE  
[Parameter(Mandatory=$true)]  
[String]$ComputerName  
)  
#Gets us the free space on the c: drive in Gbs !  
Get-WmiObject -ComputerName $ComputerName -class win32\_logicaldisk -Filter "DeviceID = ‘c:’ "

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 30, 2021, 12:15am UTC](https://forums.powershell.org/t/comment-based-help/18073/2 "2021-11-30T00:15:01Z")

</div>

Zaid,  
Welcome to the forum. 👋🏽

I’m not sure if I got what your question is. When I save the following code to a file with the path `D:\sample\test.ps1` …

```auto
<#
    .Synopsis
    This script gets you the storage space on the localhost(your computer) or remote computer for the C: drive

    .Description
    This will make things easier to grab storage information

    .Parameter ComputerName
    This is for remote and local computer

    .Example
    .\get_freespace_cdrive.ps1 -computername “Some name here”
    Shows how to do it on a remote computer

#>
[cmdletBinding()]
param(
    [Parameter(Mandatory = $true)]
    [String]$ComputerName
)
Get-WmiObject -ComputerName $ComputerName -class win32_logicaldisk -Filter "DeviceID = 'c:' "

```

And run the command …

```auto
Get-Help D:\sample\empty\Test.ps1 -Full

```

… I get the following output:

```auto
NAME
    D:\sample\empty\Test.ps1

ÜBERSICHT
    This script gets you the storage space on the localhost(your computer) or remote computer for the C: drive

SYNTAX
    D:\sample\empty\Test.ps1 [-ComputerName] <String> [<CommonParameters>]

BESCHREIBUNG
    This will make things easier to grab storage information

PARAMETER
    -ComputerName <String>
        This is for remote and local computer

        Erforderlich? true
        Position? 1
        Standardwert
        Pipelineeingaben akzeptieren?false
        Platzhalterzeichen akzeptieren?false

    <CommonParameters>
        Dieses Cmdlet unterstützt folgende allgemeine Parameter: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable und OutVariable. Weitere Informationen finden Sie unter 
        "about_CommonParameters" (https:/go.microsoft.com/fwlink/?LinkID=113216).

EINGABEN

AUSGABEN

    -------------------------- BEISPIEL 1 --------------------------

    PS C:\>.\get_freespace_cdrive.ps1 -computername “Some name here”

    Shows how to do it on a remote computer

VERWANDTE LINKS

```

The key words are in German because I have a German system 😉 but the output seems correct to me.

BTW: When you post code or sample data or console output please format it as code using the _preformatted text_ button ( **\</\>** ). Simply place your cursor on an empty line, click the button and paste your code.  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![stevething](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/stevething/32/1904_2.png) [@stevething](https://forums.powershell.org/u/stevething)\
**Post date:** [November 30, 2021, 2:36am UTC](https://forums.powershell.org/t/comment-based-help/18073/3 "2021-11-30T02:36:59Z")

</div>

[From about Comment Based Help](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-7.2#:~:text=If%20the%20first%20item%20in%20the%20script%20body%20(after%20the%20help)%20is%20a%20function%20declaration%2C%20there%20must%20be%20at%20least%20two%20blank%20lines%20between%20the%20end%20of%20the%20script%20help%20and%20the%20function%20declaration.%20Otherwise%2C%20the%20help%20is%20interpreted%20as%20being%20help%20for%20the%20function%2C%20not%20help%20for%20the%20script.)

> 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. Otherwise, the help is interpreted as being help for the function, not help for the script.

I think your problem is here:

```auto
#>
#This turns on the ability to use parameter attributes , For here it will serve the purpose of making things mandatory
[cmdletBinding()]

#paramitize so then script wont get edited
param(

```

Not enough empty lines between `[cmdletBinding()]` and the end of the help section.

---

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [November 30, 2021, 2:49am UTC](https://forums.powershell.org/t/comment-based-help/18073/4 "2021-11-30T02:49:26Z")

</div>

Hi Olaf thanks and I will keep that in mind!

Yes now if you put a comment directly above \<# then you should not get the full output but just the syntax. For example

```auto
#This is a comment
<#

#>

```

---

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [November 30, 2021, 2:50am UTC](https://forums.powershell.org/t/comment-based-help/18073/5 "2021-11-30T02:50:31Z")

</div>

The issue is at the top by \<#

I have tested out what you said has well beforehand and it does nit effect anything.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 30, 2021, 7:19am UTC](https://forums.powershell.org/t/comment-based-help/18073/6 "2021-11-30T07:19:22Z")

</div>

> [@oakzaid](#):
>
> Yes now if you put a comment directly above \<# then you should not get the full output but just the syntax.

Ok, but do you really need an additional comment line right in front of a big block comment? That’s waht I meant - I don’t understand whatfor you need this particular comment there. 😉

If you insist to have a comment line at the top of your script file you could make your code a function and add the comment base help _inline_ in this function.

---

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [November 30, 2021, 5:21pm UTC](https://forums.powershell.org/t/comment-based-help/18073/7 "2021-11-30T17:21:19Z")

</div>

I was just curios that’s all 😄  
Thanks again for your both your help!

---

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [November 30, 2021, 5:21pm UTC](https://forums.powershell.org/t/comment-based-help/18073/8 "2021-11-30T17:21:53Z")

</div>

thanks for your help! 😀

---

<div class="post-metadata">

**Author:** ![stevething](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/stevething/32/1904_2.png) [@stevething](https://forums.powershell.org/u/stevething)\
**Post date:** [November 30, 2021, 9:41pm UTC](https://forums.powershell.org/t/comment-based-help/18073/9 "2021-11-30T21:41:24Z")

</div>

So did some testing. It appears the docs are incorrect. Any comment just before the help section breaks the help section. I put 2 spaces before and after and it all works fine in PS 5.1 and 7.2.

Great catch! Olaf may also be correct about language settings. Are you using UTF8 encoding on your script files? By default PowerShell uses UTF8 for reading/writing. I tested with UTF8 and UTF16.

---

<div class="post-metadata">

**Author:** ![oakzaid](https://avatars.discourse-cdn.com/v4/letter/o/e0b2c6/32.png) [@oakzaid](https://forums.powershell.org/u/oakzaid)\
**Post date:** [December 1, 2021, 4:29pm UTC](https://forums.powershell.org/t/comment-based-help/18073/10 "2021-12-01T16:29:34Z")

</div>

Thank @stevething I think that’s what I was trying to explain but I did a poor job, sorry about that!  
The more I keep posting the better I will be able to communicate what I’m trying to explain.

Can we contact someone about this, I know its really “nothing” but it might be worth it?

Yea I haven’t changed any language settings so I should be on default.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/comment-based-help/18073/11 "2024-05-16T20:20:10Z")

</div>

Closed on May 16, 2024, 8:20pm UTC


