any ideas on how I can pass the Get-PSCallStack with out having it unroll. It appears to be a system.object[] but from what i have read online they don’t remain intact when passed and ” unroll “. I tried placing a comma in front to prevent it but that did not work.
function Pass-Callstack ([System.Object]$arg0) {
Write-Host 'Start Pass-Callstack'
$psCallStack = $arg0
$psCallStackType = $psCallStack.GetType()
$psCallStackLength = $psCallStack.Length
$psCallStackCommand0 = $psCallStack[0].command
$psCallStackCommand1 = $psCallStack[1].command
Write-Host $psCallStackType
Write-Host $psCallStackLength
Write-Host $psCallStackCommand0
Write-Host $psCallStackCommand1
$arg0 | gm
}
function Describe-Callstack {
Write-Host 'Start Describe-Callstack'
$psCallStack = (Get-PSCallStack)
$psCallStackType = $psCallStack.GetType()
$psCallStackLength = $psCallStack.Length
$psCallStackCommand0 = $psCallStack[0].command
$psCallStackCommand1 = $psCallStack[1].command
Write-Host $psCallStackType
Write-Host $psCallStackLength
Write-Host $psCallStackCommand0
Write-Host $psCallStackCommand1
$psCallStack | gm
}
Describe-Callstack
Pass-Callstack (,$psCallStack)
When you pass an argument into a Function without piping it in there is no unrolling of collections e.g.
Also, if you are expecting an array for the parameter to Pass-Callstack you can specify that like so:
Note that the use of the “System.” namespace prefix is optional. PowerShell will prepend that if it can’t find the type. Also, to specify a parameter as [object] is essentially a no-op because that is the default type. That is
[object]$arg0is the same as$arg0.You are also passing in $null into Pass-Callstack (albeit wrapped in a single element array). The variable $psCallStack is private to the function and not visible outside it unless you do prepend it with a modifier like
$script:psCallStack. In general I don’t recommend this approach. You should output $pscallstack from Describe-Callstack like so:Then assign the output of the function call to a variable:
And pass that into Pass-Callstack e.g.: