Replace a MS SQL Database in AlwaysOn AG with DBATools

There is a database in AG and you need to drop it and restore from backup (which is sometimes a transition from developer to prod )
You don’t need any prerequisite for cluster nodes and AG names.
The script find the instance in local windows server and find the db AG nodes and listener.
So finally you need the database name and the location of the backup folder which can be an Ola backup solution folder.

SQL AO AG failover in cluster group and check the synchronization status

Get info from Cluster:

Failover general example, you can use Invoke-DbaAgFailover for SQL server:

DBATools makes your life happy, you can find the SQL server instances and you can failover them.

To find  all of the SQL instances in a cluster server . To Check AG before and after the failover, and failover the SQL Server AO AG :


 

if you have to wait a lot for synchronization you can check how many servers are synchronized.


 

 

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

Continue reading “DBATools – powershell”