I am writing a PowerShell binary cmdlet in C# and trying to get the current call stack.
Looking at the internals of the Get-PSCallStack cmdlet, I can see they access an internal member (this.Context) that is not available to me:
[Cmdlet("Get", "PSCallStack", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113326")]
[OutputType(typeof (CallStackFrame))]
public class GetPSCallStackCommand : PSCmdlet
{
protected override void ProcessRecord()
{
foreach (object call in this.Context.Debugger.GetCallStack())
this.WriteObject(call);
}
}
I am trying to figure out the name of the caller’s Command and ScriptName properties.
Anyone know how to do this?