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


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.

Get-Help

From PowerShell, execute Get-Help Copy-SqlPolicyManagement -Detailed for more information on this function.

Source Code

Want to see the source code? View Copy-SqlPolicyManagement.ps1 on GitHub
 

Related commands