Clean up your dbatools

It’s easy to get the latest version of the dbatools PowerShell module:
Update-Module -Name dbatools
However, this does not remove the old versions. Those stay around until you manually do something about it.

To see all the versions installed, this command is helpful:
Get-Module -Name dbatools -ListAvailable | Select-Object Name, Version, Path

Why clean them up?
1) Remove clutter and free up space
2) Eliminates questions about exactly which version you’re running
3) Removes duplicates in the ISE Commands tab like this…

Clean it up
The process is made simple by a script included in dbatools, cleanup.ps1. It is not exposed as a public function, so you need to run it from the module directory.
You could get the full file location or change directory into the path listed for the latest version installed in the above Get-Module output and execute the cleanup.ps1 script.

There is a simpler and repeatable one-liner method that I found in one of Shawn Melton‘s GitHub comments.
It can be run with this command, in an Administrative PowerShell command window, ISE is not supported:
& "$((Get-InstalledModule dbatools).InstalledLocation)\cleanup.ps1"
It will show you the current versions, and then ask you to confirm the removal action.
Then you just have to wait for the cleanup to run (some 3rd party Anti-Virus products can slow down this step)

Confirm it
Then you just run that Get-Module command again:
Get-Module -Name dbatools -ListAvailable | Select-Object Name, Version, Path

A much cleaner set of modules!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s