Reputation: 62736
When debugging a powershell DSC resource, we have a help from the DSC resource which shows the commands needed to attach the debugger to the right Powershell Runspace. As described in https://overpoweredshell.com/Troubleshooting-DSC/:
I want to be able to output the same kind of help from my powershell script, nothing to do with DSC.
So, how do I figure out my current PSHostProcess, AppDomain and Runspace Id from my powershell script?
I do not want to debug in ISE or any other GUI (for the reasons irrelevant to the question).
Upvotes: 1
Views: 1102
Reputation: 174485
The process ID of the host process is available via the $PID
automatic variable.
The name of the containing AppDomain
can be found via:
[AppDomain]::CurrentDomain.FriendlyName
but is usually not necessary when targeting most host applications (such as powershell.exe
or powershell_ise.exe
)
For the runspaces, use Get-Runspace
from the host application:
Get-Runspace
Upvotes: 1