Questions tagged [dbatools]

This tag should be used specifically for questions related to the PowerShell toolkit/scripts known as "dbatools"

The dbatools module is a PowerShell module that started out as just Start-SqlMigration, the brainchild of PowerShell MVP, Chrissy LeMaire. It has since grown into the SQL Server DBA's best friend.

The module is comprised of hundreds of commands that make the day-to-day task of being a SQL Server DBA easier, and more efficient. The current list of commands can be found on the module's site here.

Requirements

  • PowerShell 3.0 or higher
  • SQL Server SMO (installed via SSMS generally works).
  • The majority of the migration commands (Copy-Dbaxxx) are supported against SQL Server 200.
  • Other commands validate the version of SQL Server and will output if you are connecting to an unsupported version of the command.

Getting Started

This module is hosted both in the Microsoft's PSGallery and on GitHub under the SQL Server Community Collaborative project.

The PSGallery will contain the latest "master" version which is fully tested. You can install that version by simply running:

Install-Module dbatools

You can also hit the GitHub repository and run the install.ps1. This method will download the module and install it.

Not using the GitHub method will not support utilizing the PackageManagement module to update the module (e.g. Update-Module). You will have to run the command within dbatools Update-DbaTools.

77 questions
0
votes
1 answer

Could not Load dbatools in Linux Container

I'm installing dbatools to run on a Ubuntu Container. Error: Could not import /usr/local/share/powershell/Modules/dbatools/1.1.142/bin/smo/coreclr/System.Security.SecureString.dll : Exception calling "LoadFrom" with "1" argument(s): "Could not load…
Ten Uy
  • 111
  • 1
  • 2
  • 11
0
votes
1 answer

PowerShell Comparing PSCustomObjects with the same data unexpected results

I have populated two results which I want to compare. One result comes from a SQL Server query, the other from PowerShell using the dbatools module. The results appear the same, but comparing does not return true. Some sample set up code may explain…
beehive
  • 93
  • 3
  • 11
0
votes
0 answers

PowerShell - Read values from query instead of text file to loop through set

I have a list of SQL servers that I want to loop through to test the linked servers on each SQL instance using the Test-DbaLinkedServerConnection command from dbatools and then emails the results. I have gotten the script to work when reading from a…
MISNole
  • 992
  • 1
  • 22
  • 48
0
votes
0 answers

DBATools :: where can I find the SqlInstance in PowerShell?

I want to write a script that: list all Azure Subscriptions --> and find all Azure SQL Servers list all Azure SQL Servers --> and find all Azure SQL Databases that are not master list all Azure SQL Databases --> and run the query SELECT…
0
votes
0 answers

How to generate SQL schema in dependency order using powershell dbatools?

I'm using the dbatools powershell module to generate the schema of a SQLServer database. The generated schema seems to be in alphabetical order, rather than in dependency order, so if there's a table A that has a constraint referencing table B then…
John Q Citizen
  • 321
  • 1
  • 6
  • 15
0
votes
1 answer

How can I get jobs that takes longer than 5 min using dbatools Get-DbaAgentJobHistory?

Tried running bellow command but "Duration" filter fails. Get-DbaAgentJob -SqlInstance instance_name | ` | Get-DbaAgentJobHistory -StartDate '2022-08-02' -EndDate '2022-08-03' ` | Where-Object Duration -gt [TimeSpan]'00:05:00' Error…
0
votes
2 answers

dbatools - Install-DbaInstance - ParameterBinding error

I am trying to run Install-DbaInstance in dbatools module by passing the required parameters to the command in an array (splatting), but this is returning an ParameterBindingArgumentTransformationException Code #set parameters $Computer =…
Adrian S
  • 1,007
  • 4
  • 12
  • 26
0
votes
0 answers

Load xml file to SQL Server with one column and one row from PowerShell

How can I load a XML file as a SINGLE_BLOB (i.e. single row and single column) to SQL Server with PowerShell? The code shown here works with T-SQL (column MyXml is of XML datatype): INSERT INTO dbo.MyTable (MyXML) SELECT CAST(bulkColumn AS xml)…
xhr489
  • 1,957
  • 13
  • 39
0
votes
0 answers

powershell object to string

I use powershell very few times and I would like to do something very simple ... but for which I have not found a solution. How do I remove the {} brackets from the result? From what I understand I am reading a property of the…
ACaps
  • 97
  • 1
  • 8
0
votes
2 answers

Generate Scripts for Tables and all Extended Properties

Looking for a way to generate individual scripts for each table and include any relationships or extended properties. (After getting this working I will try to generate scripts for stored procedure, and function) I am aware of the Sql-Server UI…
nonoandy
  • 120
  • 15
0
votes
1 answer

Powershell error running Get-dbaDatabase searching for missing backups

I am getting the following error when running this command: Get-dbaDatabase -sqlinstance server01 -NoFullBackup Error: Compare-DbaCollationSensitiveObject : Cannot bind argument to parameter 'Value' because it is null. At C:\Program…
packfan73
  • 1
  • 1
0
votes
1 answer

Powershell module DBATools command giving error

I am getting following error now: PS C:\WINDOWS\system32> Test-DBADbCompatibility -SqlInstance localhost -Database EfficaDB Cannot convert value "Version150" to type "Microsoft.SqlServer.Management.Smo.CompatibilityLevel". Error: "Unable to match…
0
votes
1 answer

Offline install of DBATools not working in PS 4.0

I’m trying to do an offline install of DBATools to a 2012 server. The server is on PS V4.0. I’ve been able to install it on SQL 2016 servers. I downloaded the most recent version of DBATools to my desktop and then copied it to the Powershell modules…
0
votes
1 answer

dbatools (or, SMO for SQL Server) - table ordering during schema export

I am writing a dbatools script, for exporting various items from the database schema. When using Export-DbaScript, the tables, indexes, PK/FK are dumped as expected. However, the ordering of the tables and it's constraints are dumped in the wrong…
Oyvind
  • 568
  • 2
  • 6
  • 22
0
votes
1 answer

PowerShell dbatools Invoke-DbaQuery with UNC file

Within PowerShell, I want to run the Invoke-DbaQuery dbatools command and use a UNC path with the -File parameter: Invoke-DbaQuery -SQLInstance $SQL_host -Database $DatabaseName -File "\\file_svr\scriptdir\userlist.sql" The command runs without…
Ken
  • 77
  • 9