This topic has not yet been rated - Rate this topic

Get-PSCallStack

Published: February 29, 2012

Updated: August 15, 2012

Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0

Get-PSCallStack

Displays the current call stack.

Aliases

The following abbreviations are aliases for this cmdlet:

  • gcs

Syntax


Get-PSCallStack [ <CommonParameters>]




Detailed 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, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You cannot pipe objects to this cmdlet.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.Management.Automation.CallStackFrame

    Get-PSCallStack returns an object that represents the items in the call stack.


Examples

-------------------------- EXAMPLE 1 --------------------------

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.


PS C:\>function my-alias {$p = $args[0]get-alias | where {$_.definition -like "*$p"} | ft definition, name -auto}PS C:\ps-test> set-psbreakpoint -command my-aliasCommand    : my-aliasAction     :Enabled    : TrueHitCount   : 0Id         : 0Script     : promptPS C:\ps-test> my-alias get-contentEntering 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> sget-alias | Where {$_.Definition -like "*$p*"} | ft Definition,[DBG]: PS C:\ps-test>get-pscallstackName        CommandLineParameters         UnboundArguments              Location----        ---------------------         ----------------              --------prompt      {}                            {}                            promptmy-alias    {}                            {get-content}                 promptprompt      {}                            {}                            prompt[DBG]: PS C:\ps-test> oDefinition  Name----------  ----Get-Content gcGet-Content catGet-Content type

Related topics



Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.