Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$MyInvocation.PSCommandPath unexpectedly returns $null rather than the empty string when there is no calling script. #23828

Open
5 tasks done
mklement0 opened this issue May 21, 2024 · 0 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@mklement0
Copy link
Contributor

mklement0 commented May 21, 2024

Prerequisites

Steps to reproduce

$MyInvocation.PSScriptRoot and $MyInvocation.ScriptName, which is the older equivalent of $MyInvocation.PSCommandPath, sensibly report '', i.e. the empty string in case there is no calling script.

Unexpectedly, $MyInvocation.PSCommandPath reports $null instead in this situation.
Not just for consistency with the other properties, but for consistency with PowerShell's general behavior of not using $null in string contexts, this should be fixed.

However, given that there may be existing code that explicitly tests for $null, it should at least be documented.

& { '' -eq $MyInvocation.PSCommandPath; $null -eq $MyInvocation.PSCommandPath }

Expected behavior

True
False

Actual behavior

False
True

That is, $MyInvocation.PSCommandPath unexpectedly returned $null.

Error details

No response

Environment data

PowerShell 7.5.0-preview.2

Visuals

No response

@mklement0 mklement0 added the Needs-Triage The issue is new and needs to be triaged by a work group. label May 21, 2024
@mklement0 mklement0 changed the title $MyInvocation.PSCommandPath unexpectedly return $null rather than the empty string when there is no calling script. $MyInvocation.PSCommandPath unexpectedly returns $null rather than the empty string when there is no calling script. May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

1 participant