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
0 answers

Test-DbaNetworkLatency how to load query from a script file

I am using Test-DbaNetworkLatency from dbatools (https://docs.dbatools.io/#Test-DbaNetworkLatency) to check the network latency between my application server and SQL server instance. But Test-DbaNetworkLatency command line query doesn't support…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
0
votes
1 answer

How can I run Test-DbaNetworkLatency without password prompt?

I am running Test-DbaNetworkLatency -SqlCredential sa in powershell to measure sql server network latency. It prompts input password each time I run the command. I am planning to schedule a cronjob on my server to run this command regularly so I am…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
0
votes
2 answers

How can I use the previous return to determine if I can send the alert by Powerhsell?

I'm going to use Dbatools to check my job is running or not. If it isn't running I need to send out an email alert. I only have a few backgrounds with PowerShell programming. # Import-Module D:\Tools\dbatools\dbatools.psd1 if it isn't loaded If ( !…
DBALUKE HUANG
  • 247
  • 1
  • 10
0
votes
0 answers

Invoke-DbaQuery -SqlCredential works interactively, but not when called from web app

I have a powershell script that I am calling from a Visual Studio web app (C#). I have an app pool set up, and the script executes. However, when I use any Invoke-DbaQuery command using the -SqlCredential, it works just fine from the powershell…
M Rothwell
  • 45
  • 5
0
votes
1 answer

DbaTools Error. How to fix 'Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo' when running Export-DbaInstance

I'm running Export-DbaInstance -SqlInstance $sourceServerName -Path $absPathToBackupScriptDir and getting the error 'Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo' I tried installing Microsoft Visual C++ Redistributable for…
derekbaker783
  • 8,109
  • 4
  • 36
  • 50
0
votes
1 answer

How to solve credentials conflict using dbatools

A powershell script objective is to copy a database from one server to another, then execute a simple query on destination server. the current user does not have permissions on the database servers, therefore a login was created in both servers, an…
XtianGIS
  • 967
  • 16
  • 39
0
votes
2 answers

Restore-DBADatabase and -FileMapping parameter problem

I'm trying to do a restore of a database on the same instance under a different Name and I need to replace the physical filenames of data and log files. To do this I want to use the -FileMapping parameter but I keep getting File xxx.MDF already…
dim
  • 136
  • 1
  • 12
0
votes
1 answer

What smo.ScriptingOptions properties correspond to the Generate Script Wizard's defaults?

I'm experimenting with dbatools, and comparing the output of export-dbascript to that of the SSMS "Generate Scripts" wizard. export-dbascript's behavior is controlled in part by an smo.ScriptingOptions object, and the ScriptingOptions defaults don't…
Andrew
  • 4,058
  • 4
  • 25
  • 37
0
votes
0 answers

Error: Import-DbaCsvToSql : The '++' operator works only on numbers. The operand is a 'System.IO.FileInfo'

Reference: [https://dbatools.io/functions/import-dbacsvtosql/] Trying to impact a few information into SQL Server using DBA Tools, and I get the error when I attempt to import - The rest of the script works fine, except for the…
Gabi
  • 21
  • 1
  • 6
0
votes
1 answer

DBATOOLS - Copy Data from table and create on DestinationDatabase

DbaTools Related - https://dbatools.io/functions/ Hello, I am trying to find a solution to copy a table and create it on the -Destination / -DestinationDatabase, please. I am using: Get-DbaTable -SqlInstance "Machine1" -Database DBA -Table "Table01"…
Gabi
  • 21
  • 1
  • 6
0
votes
2 answers

Powershell script scripts on dbachecks to compare the MaxMemory of server listed in a table

Run checks against servers Import-Module dbatools Import-Module dbachecks $Server = "AMCB123" $Database = "DBA" # Create recordset of servers to evaluate $sconn = new-object…
smd
  • 41
  • 1
  • 5
0
votes
0 answers

Separating a PowerShell command across SQL Server Agent job steps

I have tried without success but I suspect I have many errors at the moment. However, can anyone tell me if it is possible to separate PowerShell scripts across a series of SQL Server Agent job steps, i.e. Job 1 Step 1 --> declare & assign a…
beehive
  • 93
  • 3
  • 11
0
votes
1 answer

Invoke-Pester -CodeCoverage claims 0% code coverage when testing module function

I wrote a function for dbatools called New-DbaSqlConnectionStringBuilder. I wrote unit tests for it. I know these unit tests cover most of the function. I am getting 0% code coverage report with the following command. Invoke-Pester…
Justin Dearing
  • 14,270
  • 22
  • 88
  • 161
0
votes
1 answer

Iterate server list with dbatools?

I am really new to PowerShell and still learning so I am having a requirement to run some of the commands from dbatools and save the results. $servers = 'E:\DBA\servers.txt' $outfile = 'E:\DBA\out.csv' Get-Content $servers | ForEach-Object…
Enrique
  • 153
  • 3
  • 13
0
votes
1 answer

Filter datasets using Where-Object cmdlet

I'm looking to filter datasets with a Where-Object cmdlet. For instance, consider the Notifications column in the following cmdlet. It contains two values and I would like to filter it by Where-Object | {$_.Notifications -eq 'Operator1'}. I also…
walt
  • 3
  • 2