Posts

Showing posts from February, 2022

Reminder: You can debug PowerShell (even modules!)

Image
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