简体   繁体   English

调试在远程进程中运行的Powershell

[英]Debugging powershell running in a remote process

I have a complex system I am inheriting that uses many many powershell (.ps1) scripts as part of its complex logic. 我继承了一个复杂的系统,该系统使用许多powershell(.ps1)脚本作为其复杂逻辑的一部分。 The code is strewn about in a flat manner in a directory. 代码以扁平方式散布在目录中。 So instead of trying to piece them together and learn the system by statically reading the code, I am hoping to let it run (I have a test environment) and learn what's happening under the hood by debugging the code. 因此,我不是希望通过静态阅读代码来将它们组合在一起来学习系统,而是希望让它运行(我有一个测试环境),并通过调试代码来了解幕后发生的事情。 So this means I have to "attach" to the powershell host process and place breakpoints/step thru code. 因此,这意味着我必须“附加”到Powershell主机进程并通过代码放置断点/步骤。

Are there any tools available that make it easy to do this? 有没有可用的工具可以轻松做到这一点? I have looked at Powershell ISE, but there is no attach option. 我已经看过Powershell ISE,但是没有附加选项。 Tried VisualStudio 2013 and no dice there either (attached to Powershell_ise.exe with Script option, that didnt work either). 尝试了VisualStudio 2013,并且那里也没有骰子(通过脚本选项连接到Powershell_ise.exe,也没有用)。

Thanks for your help. 谢谢你的帮助。

You can use Set-PSDebug in your ps1 files or in base session ( documentation ). 您可以在ps1文件或基本会话( 文档 )中使用Set-PSDebug But this will be irritating process. 但这将是令人讨厌的过程。

You can use PowerShell_ISE if you run the startup/main script in the ISE's console pane (the tool window with a prompt). 如果您在ISE的控制台窗格(带有提示的工具窗口)中运行启动/主脚本,则可以使用PowerShell_ISE。 Then any breakpoints you set in the opened script files will work. 然后,您在打开的脚本文件中设置的任何断点都将起作用。 Plus you can step through the code using ISE when you've started the script in this manner. 另外,以这种方式启动脚本后,您可以使用ISE逐步执行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM