Windows 将当前正在执行的命令记录在Set PSBreakpoint的操作块中
我正在为powershell会话中的每个“Get*”附加一个命令断点。此命令断点涉及调用调用写入主机“我们被困在这段代码中”的操作。如下图所示 例如 现在不用印刷了Windows 将当前正在执行的命令记录在Set PSBreakpoint的操作块中,windows,powershell,powershell-3.0,Windows,Powershell,Powershell 3.0,我正在为powershell会话中的每个“Get*”附加一个命令断点。此命令断点涉及调用调用写入主机“我们被困在这段代码中”的操作。如下图所示 例如 现在不用印刷了 我们被困在这个代码中 我们要印刷 我们被困在这段代码中:获取运行空间 在这篇文章中,我们特别希望打印应用断点的命令ie.Get Runspace。 是否有任何方法可以在ScriptBlock中获取正在执行的命令 PS:我们在脚本块和各种其他方法中尝试了$MyInvocation.MyCommand.Name,但它们都返回null。假
我们被困在这个代码中
我们要印刷
我们被困在这段代码中:获取运行空间
在这篇文章中,我们特别希望打印应用断点的命令ie.Get Runspace。
是否有任何方法可以在ScriptBlock中获取正在执行的命令
PS:我们在脚本块和各种其他方法中尝试了$MyInvocation.MyCommand.Name,但它们都返回null。假设您对触发断点的命令行感兴趣,请使用
$MyInvocation.line
:
Set-PSBreakpoint -Command "Get-conten*" -Action {
Write-Host "We are trapped in this code: $($MyInvocation.Line)"
}
如果要检查自动
$MyInvocation
变量(类型的实例)的特定值,请将其通过管道发送到cmdlet:
Set-PSBreakpoint -Command "Get-conten*" -Action {
Write-Host "We are trapped in this code: $($MyInvocation.Line)"
}
Set-PSBreakpoint -Command "Get-conten*" -Action {
$MyInvocation | Out-Host
}