dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Export-DbaAvailabilityGroup

Exports SQL Server Availability Groups creation scripts to a T-SQL file. This is a function that is not available in SQL Server Management Studio.

Screenshots

Examples

To export all Availability Groups from SQL server “sql2012” to Documents\SqlAgExports

Export-DbaAvailabilityGroup -SqlServer sql2012

To export all Availability Groups from SQL server “sql2012”. Output scripts are witten to the C:\temp\availability_group_exports directory.

Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath C:\temp\availability_group_exports

To export Availability Groups AG1 and AG2 from SQL server “sql2012”. Output scripts are witten to the C:\dir with spaces\availability_group_exports directory.

Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath ‘C:\dir with spaces\availability_group_exports’ -AvailabilityGroups AG1,AG2

To export all Availability Groups from SQL server “sql2014”. Output scripts are witten to the C:\temp\availability_group_exports directory. If the export file already exists it will not be overwritten.

Export-DbaAvailabilityGroup -SqlServer sql2014 -FilePath C:\temp\availability_group_exports -NoClobber

Author

This command was created by Chris Sommer. You can find Chris on his blog and on Twitter.

Get-Help

From PowerShell, execute Get-Help Export-DbaAvailabilityGroup -Detailed for more information on this function.

Source Code

Want to see the source code? View Export-DbaAvailabilityGroup.ps1 on GitHub
 

Related commands