First create a file with this in it (called foo.ps1):
#!/path/to/pwsh
[cmdletbinding()]
param($Foo, $Bar)
$Foo
$Bar
chmod the file so the shebang works: chmod +x foo.ps1
start bash and invoke the ps1 with the -? asking for help:
BASH > ./foo.ps1 -?
foo.ps1 [[-Foo] <Object>] [[-Bar] <Object>] [<CommonParameters>]
works fine... now rename the file to just foo: mv foo.ps1 foo
You'll notice invoking still works:
BASH > foo 1234 "asdf"
1234
asdf
BUT Invoke the same command above:
BASH > ./foo -?
foo.ps1 [[-Foo] <Object>] [[-Bar] <Object>] [<CommonParameters>]
ParentContainsErrorRecordException: An error occurred while creating the pipeline.
Name Value
---- -----
PSVersion 7.1.0-daily.20201028
PSEdition Core
GitCommitId 7.1.0-daily.20201028
OS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Also interesting:
PS > Get-Help ./foo
Get-Help: Get-Help could not find ./foo in a help file in this session. To download updated help topics type: "Update-Help". To get help online, search for the help topic in the TechNet library at https://go.microsoft.com/fwlink/?LinkID=107116.
PS > mv foo foo.ps1
PS > Get-Help ./foo.ps1
foo.ps1 [[-Foo] <Object>] [[-Bar] <Object>] [<CommonParameters>]
cc @adityapatwardhan
Possibly related to this longstanding bug: #4217
Dup?
maybe... but this issue is more scoped to help specifically.
I'm thinking this is because of how shebangs are handled... they're read into a string:
https://github.com/PowerShell/PowerShell/blob/af8558b065ac9e9c42d61efb6174bb485170618d/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs#L1847-L1851
I'm wondering if help doesn't work on arbitrary script blocks.
Most helpful comment
Possibly related to this longstanding bug: #4217