Comment-Based Help

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.

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:’ "

Zaid,
Welcome to the forum. :wave:t4:

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

<#
    .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 …

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

… I get the following output:

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 :wink: 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

From about Comment Based Help

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:

#>
#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.

1 Like

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

#This is a comment
<#



#>

The issue is at the top by <#

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

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. :wink:

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.

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

thanks for your help! :grinning:

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.

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.