Powershell: Get-PSCallStack's Arguments script property contains no useful information

Created on 28 Nov 2019  路  3Comments  路  Source: PowerShell/PowerShell

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
Area-Cmdlets-Utility Issue-Bug Resolution-Fixed

Most helpful comment

@mklement0 Thanks! I pulled PR with fix.

All 3 comments

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

@mklement0 Thanks! I pulled PR with fix.

:tada:This issue was addressed in #11210, which has now been successfully released as v7.0.0-rc.1.:tada:

Handy links:

Was this page helpful?
0 / 5 - 0 ratings