Saturday, May 3, 2025

Working on Powershell module

Recently I wanted to improve dbatools and realised I don't know how to do Powershell module development. Specifically how to test changes of my local copy. Eventually I figured it out, so here is a short tutorial how to achieve this. I am using Powershell ISE, but from my testing it is the same with Visual Studio Code.

First I make a local copy:

PS D:\projekty> git clone https://github.com/Tisit/dbatools.git

Then I do any changes I need and save them. Afterwards I import the module I am working on:

Import-Module -Force D:\projekty\dbatools\dbatools.psm1

Since I have official dbatools installed I get now two command versions. One is the normal one, the other has dbatools\ prefix. The one with the prefix is my local copy. It can be used to test changes. If you had no module with same name, the command is imported without prefix. After any changes module needs to be reimported.

Finally the module can be removed. I found no easy way to do it, so I just select the one I don't want anymore.

Get-Module | where Name -EQ dbatools | Out-GridView -PassThru |  Remove-Module



PS. I ended up not doing anything meaningful with dbatools. Maybe next time.



No comments:

Post a Comment