dbatools

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

Github星跟踪图

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

主要指标

概览
名称与所有者dataplat/dbatools
主编程语言PowerShell
编程语言PowerShell (语言数: 3)
平台Linux, Mac, Windows
许可证MIT License
所有者活动
创建于2015-02-02 23:50:31
推送于2025-05-23 15:58:39
最后一次提交2025-05-09 10:54:47
发布数222
最新版本名称v2.1.31 (发布于 2025-05-09 10:54:33)
第一版名称v0.8.5.53 (发布于 )
用户参与
星数2.6k
关注者数156
派生数832
提交数17.4k
已启用问题?
问题数3618
打开的问题数271
拉请求数5255
打开的拉请求数12
关闭的拉请求数407
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?