如何显示当前的pshostprocess和运行空间信息?

时间:2018-07-16 15:42:11

标签: powershell debugging

调试Powershell DSC资源时,我们会从DSC资源获得帮助,其中显示了将调试器附加到正确的Powershell Runspace所需的命令。如https://overpoweredshell.com/Troubleshooting-DSC/中所述: enter image description here

我希望能够从Powershell脚本中输出相同类型的帮助,而与DSC无关。

那么,如何从powershell脚本中找出当前的PSHostProcess,AppDomain和运行空间ID?

我不想在ISE或任何其他GUI中进行调试(出于与问题无关的原因)。

1 个答案:

答案 0 :(得分:1)

可以通过$PID automatic variable获得宿主进程的进程ID。


包含AppDomain的名称可以通过以下方式找到:

[AppDomain]::CurrentDomain.FriendlyName

,但是在定位大多数主机应用程序(例如powershell.exepowershell_ise.exe)时通常不需要


对于运行空间,请从主机应用程序中使用Get-Runspace

Get-Runspace