dbatools

SQL Server 自动化和实例迁移从未如此安全、快速或自由过。「🚀 SQL Server automation and instance migrations have never been safer, faster or freer」

Github stars Tracking Chart

dbatools is PowerShell module that you may think of like a command-line SQL Server Management Studio. The project initially started out as just Start-SqlMigration.ps1, but has now grown into a collection of over 500 commands that help automate SQL Server tasks and encourage best practices.

Want to contribute to the project? We'd love to have you! Visit our contributing.md for a jump start.

Want to say thanks? Click the star at the top of the page ?

Need an invite to the SQL Community Slack workspace? Check out the self-invite page. Drop by if you'd like to chat about dbatools or even join the team!

Installer

dbatools now works on PowerShell Core (aka PowerShell 6+). This means that you can run a large majority of our commands on Linux and macOS ??

Run the following to install dbatools from the PowerShell Gallery (to install on a server or for all users, remove the -Scope parameter and run in an elevated session):

Install-Module dbatools -Scope CurrentUser

If you don't have a version of PowerShell that supports the PowerShell Gallery, you can install it manually:

Invoke-Expression (Invoke-WebRequest https://dbatools.io/in)

Note: please only use Invoke-Expression (Invoke-WebRequest..) from sources you trust, like us ?

Usage scenarios

In addition to the simple things you can do in SSMS (e.g. starting a job, backing up a database), we've also read a whole bunch of docs and came up with commands that do nifty things quickly.

  • Lost sysadmin access and need to regain entry to your SQL Server? Use Reset-DbaAdmin.
  • Need to easily test your backups? Use Test-DbaLastBackup.
  • SPN management got you down? Use our suite of SPN commands to find which SPNs are missing and easily add them.
  • Got so many databases you can't keep track? Congrats on your big ol' environment! Use Find-DbaDatabase to easily find your database.

Usage examples

As previously mentioned, dbatools now offers over 500 commands! Here are some of the ones we highlight at conferences.

PowerShell v3 and above required. (See below for important information about alternative logins and specifying SQL Server ports).

# Set some vars
$new = "localhost\sql2016"
$old = $instance = "localhost"
$allservers = $old, $new

# Alternatively, use Registered Servers
$allservers = Get-DbaCmsRegServer -SqlInstance $instance

# Need to restore a database? It can be as simple as this:
Restore-DbaDatabase -SqlInstance $instance -Path "C:\temp\AdventureWorks2012-Full Database Backup.bak"

# Use Ola Hallengren's backup script? We can restore an *ENTIRE INSTANCE* with just one line
Get-ChildItem -Directory \\workstation\backups\sql2012

Overview

Name With Ownerdataplat/dbatools
Primary LanguagePowerShell
Program languagePowerShell (Language Count: 3)
PlatformLinux, Mac, Windows
License:MIT License
Release Count205
Last Release Namev2.1.14 (Posted on )
First Release Namev0.8.5.53 (Posted on )
Created At2015-02-02 23:50:31
Pushed At2024-05-03 12:06:21
Last Commit At2024-04-12 17:45:43
Stargazers Count2.3k
Watchers Count158
Fork Count782
Commits Count17.2k
Has Issues Enabled
Issues Count3471
Issue Open Count242
Pull Requests Count5125
Pull Requests Open Count2
Pull Requests Close Count398
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top