I write a lot about SQL Server automation, and dbatools comes up constantly. Instead of rewriting the install steps in every post, I’m putting them here once so I can just point back.
The full instructions live on the official site: dbatools.io/download. If you’re new to dbatools, follow those first, they’re always up to date. You should also check out their Getting Started page: dbatools.io/getting-started while you’re there since it has tons of great examples to give you ideas for your next automation project.
The gist is simple though:
Install-Module dbatools -Scope CurrentUser
-Scope CurrentUser is doing something worth noticing. It installs into your profile rather than into Program Files, so you don’t need an elevated session for it. Drop the scope and it goes machine-wide for every account on the box, which does need admin. I use CurrentUser on anything I don’t own and AllUsers on a jump box where the point is that everyone has it. The catch with CurrentUser is that a scheduled task or an Agent job running under a service account won’t see it, because it’s installed for me and not for that account, and that’s caught me out more than once.
If you’re prompted about trusting the repository, say yes… it’s the official source. On older systems you may also need to explicitly trust PSGallery with:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Check that it worked:
Get-Command -Module dbatools
Keep it updated periodically with this command:
Update-Module dbatools
Note: If you run into errors about script execution policy, you may need to allow PowerShell to run downloaded modules. The simplest way is:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUserThat lets you run modules you install from the Gallery while still keeping protections in place.
That’s really all you need for most modern cases. For older versions of Windows or locked-down environments, see the alternate installation methods listed on the official download page.