question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get-Help does not work for script files containing using statements.

See original GitHub issue

Steps to reproduce

Create a script file test.ps1 with the following content:

using namespace System.Management.Automation

<#
.SYNOPSIS
A simple script for problem reproduction.
#>
Param ($SampleParam)

Execute following command:

> Get-Help .\test.ps1

Expected behavior

Get-Help .\test.ps1

NAME
    ...\test.ps1

SYNOPSIS
    A simple script for problem reproduction.


SYNTAX
    ...\test.ps1 [[-SampleParam] <Object>] [<CommonParameters>]


DESCRIPTION


RELATED LINKS

REMARKS
    To see the examples, type: "Get-Help ...\test.ps1 -Examples"
    For more information, type: "Get-Help ...\test.ps1 -Detailed"
    For technical information, type: "Get-Help ...\test.ps1 -Full"

Actual behavior

> Get-Help .\test.ps1
test.ps1 [[-SampleParam] <Object>]

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.7
PSEdition                      Core
GitCommitId                    7.1.0-preview.7-10-g3effa204103460c996a8612aa70718fdf924047d
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
doctordnscommented, Sep 22, 2020

I wish that Help was more intelligent - and gave an error when it fails rather than no output.

2reactions
jhoneillcommented, Sep 22, 2020

Comment based help must be the first or last thing in the file or in the block for a function, so it comes before the using statement

<#
.SYNOPSIS
A simple script for problem reproduction.
#>
using namespace System.Management.Automation
Param ($SampleParam)
[enum]::GetNames([actionPreference])

Works.

function test-this {
[alias("Test")]
<#
.SYNOPSIS
A simple script for problem reproduction.
#>
Param ($SampleParam)
}

Gives no help

function test-this {
<#
.SYNOPSIS
A simple script for problem reproduction.
#>
[alias("Test")]
Param ($SampleParam)
}

Works.

I would be careful with a change like this which will enable some behavior in new versions but neither works nor errors/warns in old ones. It seems logical to say those things should be allowed in any order. However when someone takes a script with an order which works in 7.1 and tries to run it on an earlier version they will go crazy trying to figure out why it doesn’t work in Windows PowerShell or in something with PowerShell 7.0.2 embedded (like .NET interactive) .

The rules that using can be preceded by comments, and comment based help must be first or last have been there since the features were introduced.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to add script notes (Get-Help) but not working
Solution: Looks like the issue is coming from you using .SYNTAX, which isn't a legal keyword for comment based help.
Read more >
How to enable a PowerShell script to return help text when ...
1 Answer 1 ... To clairfy, just copy and paste this to the top of your script. You can also do this for...
Read more >
Get-Help (Microsoft.PowerShell.Core)
To get help for a script that isn't located in a path that's listed in the $env:Path environment variable, type the script's path...
Read more >
Troubleshooting | Apps Script
There is an error in your script that doesn't have a corresponding error message. Try debugging your script and see if you can...
Read more >
Choosing and Setting a PowerShell Execution Policy
With this policy set, your computer will run those PowerShell scripts that are accompanied by a valid signed with a valid digital signature...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found