Stepping through Powershell Code, Modules
I ran into a few issues when modifying my PowerShell modules and not being able to step through the modified code. Here are some simple tips to ensure you can debug your modified powershell code.
Option A – VS Code
1. Use VS Code, with the Powershell extension
2. In the terminal provided at the bottom, CD to the folder that contains your source ps1 (or psm1) file
The reason this CD is important is because it doesn’t behave the same when you have the terminal prompt start in your default user folder.
3. Now you should be able to step through and have it pick up the latest code changes – including those in your modules. Make sure you Remove-Module (in your code, or manually), before testing a new module.
Option B – From a PowerShell Administrator Prompt
This has several advantages – especially if you are prompting the user for input. The input popup is easier to work with.
Also, this doesn’t have the overhead of the debugger, and will generally run faster.
Install-Module –Force
Remember, you can force install your new module, in case the old one is causing conflicts.
Leave a Reply