On the first day of Christmas dbatools gave to me: Find-DbaCommand
On the second day of Christmas dbatools gave to me: Get-DbaCmsRegServer
On the third day of Christmas dbatools gave to me: DbaMaxMemory
On the fourth day of Christmas dbatools gave to me: DbaAgentJob
On the fifth day of Christmas dbatools gave to me: DbaLogin
On the sixth day of Christmas dbatools gave to me: DbaTempDbConfig
On the seventh day of Christmas dbatools gave to me: DbaAgentAlert
On the eighth day of Christmas dbatools gave to me: DbaDbCompression
On the ninth day of Christmas dbatools gave to me: Backup-DbaDatabase
On the tenth day of Christmas dbatools gave to me: Restore-DbaDatabase
On the eleventh day of Christmas dbatools gave to me: New-DbaAvailabilityGroup
Command Information:
We are getting down to the end of the series and I have saved some of my favorite commands for last. This eleventh day will focus on the new commands recently released focusing on SQL AlwaysOn Availability Groups. My environment relies heavily on AG’s and we have learned a lot about them over the years. However, these dbatools commands take things to another level. With these commands dbatools can automate the building, rebuilding, adjusting or almost any management of an AG you can think of. Want to remove a database from an AG, restore it, then add it back to all replicas, there is a group of commands at your disposal. Think of it and you can do it, or suggest it and it can probably be added in future releases.
Command Description:
New-DbaAvailabilityGroup
Automates the creation of availability groups.
* Checks prerequisites
* Creates Availability Group and adds primary replica
* Grants cluster permissions if necessary
* Adds secondary replica if supplied
* Adds databases if supplied
* Performs backup/restore if seeding mode is manual
* Performs backup to NUL if seeding mode is automatic
* Adds listener to primary if supplied
* Joins secondaries to availability group
* Grants endpoint connect permissions to service accounts
* Grants CreateAnyDatabase permissions if seeding mode is automatic
* Returns Availability Group object from primaryNOTE: If a backup / restore is performed, the backups will be left intact on the network share.
Thanks for this, Thomas Stringer! https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/29/set-up-an-alwayson-availability-group-with-powershell/
Command Example:
1 2 3 4 5 |
New-DbaAvailabilityGroup -Primary REGDBADBS01A -Secondary REGDBADBS01B ` -Name dbatools_AG -ClusterType Wsfc -AutomatedBackupPreference Primary ` -Database dbatools -SharedPath \\REGDBADBS01A\S$\Backups ` -FailoverMode Automatic -AvailabilityMode SynchronousCommit ` -Confirm:$false |
It is as easy as that, and now we have a 2 node AG with the dbatools database being synchronized across the nodes.
Advanced Command Usage:
Now lets say we don’t want our secondary to be automatic failover and synchronous commit mode.
1 2 3 |
Set-DbaAgReplica -SqlInstance REGDBADBS01A -Replica REGDBADBS01B ` -AvailabilityGroup dbatools_AG -AvailabilityMode AsynchronousCommit ` -FailoverMode Manual |