Get-PSCallStack

NAME
    Get-PSCallStack

SYNOPSIS
    Displays the current call stack.

SYNTAX
    Get-PSCallStack [<CommonParameters>]

DESCRIPTION
    The Get-PSCallStack cmdlet displays the current call stack.

    Although it is designed to be used with the Windows PowerShell debugger, you can use this cmdlet to display the call stack in a script or Function outside of the debugger.

    To run a Get-PSCallStack command while in the debugger, type “k” or “Get-PSCallStack“.

PARAMETERS
    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe objects to this cmdlet.

OUTPUTS
    System.Management.Automation.CallStackFrame
        Get-PSCallStack returns an object that represents the items in the call stack.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>function my-alias {
     $p = $args[0]
     Get-Alias | where {$_.definition -like “*$p”} | ft 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:\ps-test> 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*”} | ft Definition,

    [DBG]: PS C:\ps-test>Get-PSCallStack

    Name        CommandLineParameters         UnboundArguments             Location
    —-        ———————         —————-             ——–
    prompt     {}                            {}                            prompt
    my-alias    {}                            {Get-Content}                 prompt
    prompt     {}                            {}                            prompt

    [DBG]: PS C:\ps-test> o

    Definition Name
    ———- —-
    Get-Content gc
    Get-Content cat
    Get-Content type

    Description
    ———–
    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 Windows 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.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113326
    about_debuggers
    Set-PSBreakpoint
    Get-PSBreakpoint
    Enable-PSBreakpoint
    Disable-PSBreakpoint
    Remove-PSBreakpoint