PowerShell not reading comment-based help section correctly - Stack Overflow
I'm having a really weird problem with help in my module. (this is the third one I'm building and the first time I'm seeing this.)
Pertinent section:
Having a weird comment-based help issue in a module i’m building. Currently, the help looks like:
#!/usr/bin/env pwsh
<#
.DESCRIPTION
This script is a bridge between PowerShell and the AppleScript Choose File UI primitive. It allows the use of the standard macOS Choose File dialog inside a PowerShell script and returns a string array of POSIX-Compliant file paths.
#>
<rest of module>
But when I run Get-Help on it, it says it can’t find the help. I’m at a real loss here.
This is current PowerShell running on macOS, and the other two modules i've done, I've never seen this issue before.
I'm having a really weird problem with help in my module. (this is the third one I'm building and the first time I'm seeing this.)
Pertinent section:
Having a weird comment-based help issue in a module i’m building. Currently, the help looks like:
#!/usr/bin/env pwsh
<#
.DESCRIPTION
This script is a bridge between PowerShell and the AppleScript Choose File UI primitive. It allows the use of the standard macOS Choose File dialog inside a PowerShell script and returns a string array of POSIX-Compliant file paths.
#>
<rest of module>
But when I run Get-Help on it, it says it can’t find the help. I’m at a real loss here.
This is current PowerShell running on macOS, and the other two modules i've done, I've never seen this issue before.
Share Improve this question asked 16 hours ago johncwelchjohncwelch 213 bronze badges 5 |1 Answer
Reset to default 2As stated in the helpful comments from mklement0:
- The shebang line is irrelevant in this context
- Comment-based help doesn't apply to a module but to function (aka command) exported by the module
The comment base help might be either prior the concerned function:
Remove-Module Get-DisplayDialog -ErrorAction SilentlyContinue
{
<#
.DESCRIPTION
This script is a bridge between PowerShell and the AppleScript Choose File UI primitive. It allows the use of the standard macOS Choose File dialog inside a PowerShell script and returns a string array of POSIX-Compliant file paths.
#>
function Get-DisplayDialog { }
Export-ModuleMember -Function Get-DisplayDialog
} | Set-Content -Path .\Get-DisplayDialog.psm1
Import-Module .\Get-DisplayDialog.psm1
or embedded in the the top of the function:
Remove-Module Get-DisplayDialog -ErrorAction SilentlyContinue
{
function Get-DisplayDialog {
<#
.DESCRIPTION
This script is a bridge between PowerShell and the AppleScript Choose File UI primitive. It allows the use of the standard macOS Choose File dialog inside a PowerShell script and returns a string array of POSIX-Compliant file paths.
#>
}
Export-ModuleMember -Function Get-DisplayDialog
} | Set-Content -Path .\Get-DisplayDialog.psm1
Import-Module .\Get-DisplayDialog.psm1
After pasting either of the examples above into a PowerShell host or terminal, you might get the help of the specific exported function:
Get-Help Get-DisplayDialog
NAME
Get-DisplayDialog
SYNOPSIS
SYNTAX
Get-DisplayDialog [<CommonParameters>]
DESCRIPTION
This script is a bridge between PowerShell and the AppleScript Choose File UI primitive. It allows the use of the standard macOS Choose File dialog
inside a PowerShell script and returns a string array of POSIX-Compliant file paths.
...
There are two pitfalls to mention here that might have lead to some confusion:
If the module is already imported and loaded, you will need to remove it (
Remove-Module Get-DisplayDialog -ErrorAction SilentlyContinue
) or open a new PowerShell session in order to see the new result.Your exported function has the same name as the module (
Get-DisplayDialog
), there is nothing wrong with that, but to be clear: you aren't retrieving the help of the module but the help of the exported function(s).
- 台式电脑“玩”安卓(图)
- 仅售74美元的Android迷你电脑:你会买吗?
- 抓住“苹果”的尾巴,国产平板的突围之路
- How to efficiently read HDF5 file using NetCDF-java - Stack Overflow
- The uid generator is giving negative value(-8201645565344219221) and using this implementation DefaultUidGenerator.java to gener
- c# - TrackableBehaviour.Status type is missing when using Vuforia - Stack Overflow
- java - I have an issue with tmcbeans, I can not run projects - Stack Overflow
- python - Issues with getting Tensorflow to work with RTX 4060 Laptop - Stack Overflow
- c# - Is there a way to fill scriptable object field with a child class? - Stack Overflow
- c++ - std::rethrow_exception with std::current_exception - Stack Overflow
- Why is Django Machina query altered with nonexistent table name - Stack Overflow
- c# - IdentityServer4 and returning an error in response - Stack Overflow
- swift - How to set axis order in AxisMarks in SwiftUI Chart view - Stack Overflow
- Scene Appears Completely Black on Android Build Despite Correct UI Rendering in Unity Editor - Stack Overflow
- javascript - mapBox autofill sessionToken usage? - Stack Overflow
- micropython - Bidirectional communication over USB between host PC and Raspberry Pi Pico - Stack Overflow
- arkit - Detecting and Using 2 Different Vertical Planes - Stack Overflow
$env:PATH
, which isn't what modules do. If your script is a(n executable) shell script discoverable via$env:PATH
, the comment-based help should work; if it isn't, targeting it by its path should work. Please edit your question to clarify your scenario. – mklement0 Commented 14 hours ago.psm1
file, ever. And, indeed, the presence or absence of a shebang line is irrelevant in this context. More importantly, you shouldn't expect comment-based help in the top-level scope - as opposed to in the context of functions exported from this module - in such a file to be honored. Please explain why you do have this expectation. – mklement0 Commented 12 hours ago