Reminder: You can debug PowerShell (even modules!)


Scenario

I made a small change in a COMMENT in a PowerShell module.


Result

Our build server puked on me. I rebuilt a couple of times, 'cause "I didn't do anything!" Slight frustration.


Fix

OK, find the offending code (CTRL+G in VSCode to go to the exact line). Some "Export-NUnitXml" function exported from a PowerShell Module.

- Declare all variables up to the point of the failure

- Add a breakpoint: Set-PSBreakpoint -script ".\.build\tasks\Export-NUnitXml.psm1" -Line 21

- Run the function in VSCode's terminal

- Breakpoint hit.

- Find offensive code that just decided to show up today

- Fix it.


Debugging makes things easier.



But wait, there's more 😅

If you're making changes to PowerShell Modules, remember that you have to reload them before you see your changes in your session. Or in other words: Edit Code > Save > Import-Module -Force

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints