Get-PSCallStack

Display the current call stack.

Syntax
      Get-PSCallStack [CommonParameters]

Key

Standard Aliases for Get-PSCallStack: gcs

Examples

Get the call stack for a function:

PS C:\> function my-alias {
    $p = $args[0]
    Get-Alias | where {$_.definition -like "*$p"} | format-table definition, name -auto
    }

PS C:\ps-test> Set-PSBreakpoint -Command my-alias
 Command    : my-alias
 Action     : 
 Enabled    : True
 HitCount   : 0
 Id         : 0
 Script     : prompt PS C:\>my-alias Get-Content
    
 Entering debug mode. Use h or ? for help.
 Hit Command breakpoint on 'prompt:my-alias'
 my-alias get-content

 [DBG]: PS C:\ps-test> s
 $p = $args[0]
 DEBUG: Stepped to ':    $p = $args[0]    '
 [DBG]: PS C:\ps-test> s
 get-alias | Where {$_.Definition -like "*$p*"} | format-table Definition,

 [DBG]: PS C:\ps-test> get-pscallstack
    
    Name        CommandLineParameters         UnboundArguments              Location
    ----        ---------------------         ----------------              --------
    prompt      {}                            {}                            prompt
    my-alias    {}                            {get-content}                 prompt
    prompt      {}                            {}                            prompt PS C:\>[DBG]: PS C:\ps-test> o
    Definition  Name
    ----------  ----
    Get-Content gc
    Get-Content cat
    Get-Content type

This command uses the Get-PSCallStack cmdlet to display the call stack for My-Alias, a simple function that gets the aliases for a cmdlet name.

The first command enters the function at the PowerShell prompt. The second command uses the Set-PSBreakpoint cmdlet to set a breakpoint on the My-Alias function. The third command uses the My-Alias function to get all of the aliases in the current session for the Get-Content cmdlet.

The debugger breaks in at the function call. Two consecutive step-into (s) commands begin executing the function line by line. Then, a Get-PSCallStack command is used to retrieve the call stack. The final command is a Step-Out command (o) that exits the debugger and continues executing the script to completion.

"Take the back roads instead of the highways" ~ Minnie Pearl

Related PowerShell Cmdlets:

Enable-PSBreakpoint - Enable a breakpoint in the current console.


 
Copyright © 1999-2021 SS64.com
Some rights reserved