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


Copy-Audit

Migrates audits from one SQL Server to another. By default, all audits are copied.

The -Audits parameter is autopopulated for command-line completion and can be used to copy only specific audits.

If the audit already exists on the destination, it will be skipped unless -Force is specified. Force drops and recreates the object. Dependencies are not currently copied over.

Examples

To copy all audits from sqlserver2014a to sqlcluster, using Windows audits. If audits with the same name exist on sqlcluster, they will be skipped.

To copy only two audits, LoginAudit and TableModAudit, from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and integrated (Windows) authentication for sqlcluster. If an audit with the same name exists on sqlcluster, it will be dropped and recreated because -Force was used.

To see what would happen if the command were executed. No actions are actually performed.

From PowerShell, execute   Get-Help Copy-SqlAudit -Detailed   for more information on this function. Want to see the source code? See it on GitHub