Installing Old Versions of PowerShell Modules with Their Dependencies

Page content

I don’t recall where this came up (probably in SQLSlack), but I had a need to install an older version of dbatools to test something related to loading the dbatools.library library/dependency.

Down Memory Lane

My first thought was to run Install-Module -Name dbatools -RequiredVersion 2.1.31 and let it roll. But that didn’t work out.

Screenshot of PowerShell installing a specific version of a module with Install-Module

The required version of dbatools was installed, but Install-Module didn’t install the correct version of the dependency.

Then I remembered PSResourceGet, the replacement for PowerShellGet that all of us using PowerShell 7.x probably should have moved to a while ago.

The usage here is pretty similar, I just need to call the new function name Install-PSResource and change -RequiredVersion to -Version

Screenshot of PowerShell installing a specific version of a module with Install-PSResource

And there’s the old version of dbatools.library that I was looking for! Now I can go ahead and test the older dbatools properly. After I sort out how to get the older dbatools to load that version of library instead of the newer one, that is. The path of least resistance is to just delete the older items and let the module function like it did when 2.1.31 was the new hotness.

Where To Next?

It’ll take a bit for me to correct the muscle memory but this is a change to my workflow that should happened a while ago. PSResourceGet was released in October 2023 and while the functionality most have used in PowerShellGet is still there, this new module’s functions cover more than just modules so it’ll be handy for other uses.