Write-Host "To start debugging execute the following commands in a PS-Console" Write-Host "**** Script is running in debugging mode ****" $aFile = "$PSScriptRoot\long-running.ps1"Įcho " PowerShell: $($psversiontable.PsVersion)"Įcho ". You can work-around this by using a helper script which executes your script. Thats not what I want, I want PowerShell ISE. When I add the Wait-Debugger statement the PowerShell console running the script breaks at the statement in the cmd-line debugger of PowerShell. Say I want to run a script and let it break at some point with the Wait-Debugger statement and continue debugging with PowerShell ISE. The implementation of PowerShell runspaces gives us a lot of flexibility and allows for some crazy scenarios. ![]() If you want more details about this functionality lookup the following commands on Microsofts site.Įnter-PSHostProcess, Get-Runspace, Debug-Runspace, Enable-RunspaceDebug -BreakAll, Wait-Debugger, Enter-PSSession ![]() Before using Enter-PSHostProcess open a session with Enter-PSSession -ComputerName and follow the same steps. If your script is running on another machine and PowerShell remoting is configured you can also do this with remote scripts. Start this script in a PowerShell console and start PowerShell ISE with the following commands Enter-PSHostProcess -id 14468 # enter here your script pid To test this scenario create a long running script like this Write-Host "Long running script with PID: $pid" Now you can run it again after inspection or continue debugging it and/or set breakpoints. PowerShell ISE will now load the script and show it halted at the currently executed statement. Enter Debug-Runspace -id 1 (most of the time it's Runspace 1).Now start PowerShell ISE and activate the console (Ctrl-D). ![]() First find the process id of the running script in the taskmanager details tab (PID).Now you can in PowerShell 5.0 with the following steps. Debug a PowerShell script running in PowerShell console locally or remote after it has started 5 April, 2017Īlways wanted to debug a running PowerShell script in a console which looks like it's stuck on something.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |