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


Copy-PolicyManagement

This function migrates SQL Policy Based Management Objects, including both policies and conditions from one SQL Server to another. By default, all policies and conditions are copied.

The -Policies and -Conditions parameters are autopopulated for command-line completion and can be used to copy only specific objects.

If an object already exist on the destination, it will be skipped unless -Force is specified. Force drops and recreates the object.

Examples

To copy all policies and conditions from sqlserver2014a to sqlcluster, using Windows credentials.

To copy all policies and conditions from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and Windows credentials for sqlcluster.

Copies only one policy, ‘xp_cmdshell must be disabled’ from sqlserver2014a to sqlcluster. No conditions are migrated.

Shows what would happen if the command were executed. This does not perform any actions.

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