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.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.