Skip to content

Get-PSCallStack's Arguments script property contains no useful information #11208

Closed

Description

The .Arguments property on the System.Management.Automation.CallStackFrame instances output by Get-PSCallStack is a script property that - I presume - is meant to reflect the arguments passed.

The property isn't documented, but it seems to contain no useful information, seemingly containing $null in any non-global scope.

While you con obtain argument information via the type-native .InvocationInfo property, I assume there is a purpose to .Arguments that it currently doesn't fulfill.

Steps to reproduce

& { (Get-PSCallStack)[0].Arguments } 'foo'  | Should -match 'foo'

Expected behavior

The test should pass.

Actual behavior

The test fails, because .Arguments is $null:

Expected regular expression 'foo' to match $null, but it did not match.

Environment data

PowerShell Core 7.0.0-preview.6

Activity

  1. added
    Issue-Question
    on Nov 28, 2019
  2. SeeminglyScience commented on Nov 28, 2019

    @SeeminglyScience
    Contributor

    Looks like that script property got hit by the script that was replacing "" with string.Empty.

    The line was (and is in Windows PowerShell):

    foreach ($arg in $this.InvocationInfo.UnboundArguments.GetEnumerator())
    {
    if ($argumentsBuilder.Length -gt 1)
    {
    $argumentsBuilder.Append(", ")
    }
    # etc...

    But is now

    foreach ($arg in $this.InvocationInfo.UnboundArguments.GetEnumerator())
    {
    if ($argumentsBuilder.Length -gt 1)
    {
    $argumentsBuilder.Append(string.Empty, string.Empty)
    }
    # etc...

    Which is a syntax error.

    You can see it with (Get-PSCallStack)[0].psobject.Properties['Arguments'].GetterScript

  3. added
    Issue-Bug
    and removed
    Issue-Question
    on Nov 28, 2019
  4. iSazonov commented on Nov 28, 2019

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) Thanks! I pulled PR with fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions