DBATools – powershell

Taking notes – some example:

Download and Install to my computer:

https://dbatools.io/download/

­

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Install-Module dbatools

if necessary:
update-module dbatools

OFFLINE:

Copy this directory to offline server:
C:\Program Files\WindowsPowerShell\Modules\dbatools

Set-Location ‘C:\Program Files\WindowsPowerShell\Modules\dbatools’ ##.\install.ps1  ## with internet access
Get-ChildItem -Recurse | Unblock-File

Import module in the server :
Import-Module .\dbatools.psd1

Finds SQL instances:
Get-Content .\servers.txt | Find-DbaInstance -ScanType Browser
Find-DbaInstance -DiscoveryType DataSourceEnumeration

Default SQL server path:
Get-Content .\sql-servers.txt | Get-DbaDefaultPath
Get-DbaLastBackup -SqlInstance servername\instancename
Get-Content .\sql-servers.txt | Get-DbaAgHadr

Get-DbaDiskSpace

Get-Content .\servers.txt | Get-DbaDiskSpace  |  Export-Csv -Path .\serverdiskspace.csv

Get-Content .\sql-servers.txt | Test-DbaConnection   |  Export-Csv -Path .\server-dbaconnection.csv

Get-Content .\sql-all.txt | Get-DbaDatabase|  Export-Csv -Path .\databases04.csv

Find-DbaDbGrowthEvent  -SqlInstance servername\instance | Out-GridView

Find-DbaDbGrowthEvent  -SqlInstance localhost | Out-GridView

Get-Content otc_list.txt | foreach-object { Invoke-DbaQuery -SqlInstance $_   -Query ‘select @szerver, @@servername’ -sqlparameters @{szerver= $_} } | Export-Csv result_list.txt

Leave a Reply

Your email address will not be published. Required fields are marked *