SQL Server Tips

How to Install DBATools Powershell Module for SQL Server [Full Guide]

Updated
4 min read
Written by
Mark Varnas

What is dbatools and PowerShell?

Dbatools is an open-source module of PowerShell developed by big names from the SQL Server community, MVPs, and other SQL Server and PowerShell professionals. The dbatools uses SMO (server management objects) from the .Net framework, the same objects used bu SSMS (SQL Server management studio).

With SMO objects, we can manipulate any SQL Server object using the C# program language. In addition to SMO’s widespread use, dbatools use the WMI/CIM (Windows Management Instrumentation/Common Information Model) to manipulate windows server objects.

With all this power, it is focused on the administrative tasks of SQL Server environments, implementing good practices for development, migration, and daily routines. dbatools.io currently has more than 500 commands to assist you in your daily activities.

How to install dbatools?

There is only one requirement: PowerShell v3+

Once you meet these requirements, installation is simple:

  • Open PowerShell command window with Administrator rights (Right Click on Window and select run as an administrator).
  • Run the following command: Install-Module dbatools.
  • To give affirmative answers to the questions type Y (Yes) in the prompt.

That’s it! You are done.

Installing dbatools offline

You can also use the offline method to install in your server when you don’t have internet access.

  • First, download the package on dbatools.io/zip and copy it preferably to some path that is configured in your environment variable $ env: PSModulePath.
  • Open the Start Search, type in “env”, and choose Edit the system environment variables.
  • Click the Environment Variables… button
  • After copying the package to one of the above locations, you can install dbatools using the command:
    • Import-Module -Name dbatools

How to check if dbatools was correctly installed?

One way is to use the Get-Module command presented below.

  • Get-Module dbatools -ListAvailable

If you don’t receive that message, it may mean that the module is not installed on the machine or has not been loaded into the memory yet.

Getting started with dbatools

Let’s navigate through PowerShell using the native cmdlets. Below are some commands that you will use in your everyday life.

  • Get-Command – List all package commands installed in the machine.
  • Get-Help – Get command details.
  • Get-command -Module dbatools – List all commands from dbatools module.
  • Get-command *Get-DbaSQL* – To filter the search, use the asterisk (*) wildcard character with the Name parameter.
  • Get-Help Get-DbaSqlService -Examples – The Examples parameter displays the help file’s NAME and SYNOPSIS sections and all the Examples, as you can see below:

Get-Help Get-DbaSqlService -Detailed – The Detailed parameter displays the help article’s detailed view that includes parameter descriptions and example, as you can see below:

The better your knowledge of PowerShell is, the easier it will be to work with dbatools, and the easier it will be to extract rich information.

More information

The dbatools commands automate and simplify many of the tasks we’ve all had to do multiple times. Want to know more? Here are some great articles that focus on functionality:

Conclusion

PowerShell is everywhere. Learning PowerShell prepares you for the inevitable (and fun!) automation-rich future. Once you learn how to use an automation tool like PowerShell, you can easily transition your skills to automate everything from on-premise Instances (Windows/Linux) to the Azure SQL Database (it even helps power the cloud).

Speak with a SQL Expert

In just 30 minutes, we will show you how we can eliminate your SQL Server headaches and provide 
operational peace of mind

Article by
Mark Varnas
Founder | CEO | SQL Veteran
Hey, I'm Mark, one of the guys behind Red9. I make a living performance tuning SQL Servers and making them more stable.

Leave a Comment

Discover More

SQL Server Health Check SQL Server Migrations & Upgrades SQL Server Performance Tuning SQL Server Security SQL Server Tips

Discover what clients are saying about Red9

Red9 has incredible expertise both in SQL migration and performance tuning.

The biggest benefit has been performance gains and tuning associated with migrating to AWS and a newer version of SQL Server with Always On clustering. Red9 was integral to this process. The deep knowledge of MSSQL and combined experience of Red9 have been a huge asset during a difficult migration. Red9 found inefficient indexes and performance bottlenecks that improved latency by over 400%.

Rich Staats 5 stars
Rich Staats
Cloud Engineer
MetalToad

Always willing to go an extra mile

Working with Red9 DBAs has been a pleasure. They are great team players and have an expert knowledge of SQL Server database administration. And are always willing to go the extra mile to get the project done.
5 stars
Evelyn A.
Sr. Database Administrator

Boosts server health and efficiency for enhanced customer satisfaction

Since adding Red9 to the reporting and DataWarehousing team, Red9 has done a good job coming up to speed on our environments and helping ensure we continue to meet our customer's needs. Red9 has taken ownership of our servers ensuring they remain healthy by monitoring and tuning inefficient queries.
5 stars
Andrew F.
Datawarehousing Manager
See more testimonials

Check Red9's SQL Server Services

SQL Server Consulting

Perfect for one-time projects like SQL migrations or upgrades, and short-term fixes such as performance issues or SQL remediation.

Discover More ➜

SQL Server Managed Services

Continuous SQL support, proactive monitoring, and expert DBA help with one predictable monthly fee.

Discover More ➜

Emergency SQL Support

Take the stress out of emergencies with immediate access to a SQL Server Sr. DBA 24x7x365

Discover More ➜
Explore All Services