commands

^

Copy-DbaPolicyManagement

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Copy-DbaPolicyManagement on GitHub.
Want to see the Bill Of Health for this command? Check out Copy-DbaPolicyManagement.

Synopsis

Migrates SQL Policy Based Management Objects, including both policies and conditions.

Description

By default, all policies and conditions are copied. If an object already exist on the destination, it will be skipped unless -Force is used.

The -Policy and -Condition parameters are auto-populated for command-line completion and can be used to copy only specific objects.

Syntax

Copy-DbaPolicyManagement
    [-Source] <DbaInstanceParameter>
    [[-SourceSqlCredential] <PSCredential>]
    [-Destination] <DbaInstanceParameter[]>
    [[-DestinationSqlCredential] <PSCredential>]
    [[-Policy] <Object[]>]
    [[-ExcludePolicy] <Object[]>]
    [[-Condition] <Object[]>]
    [[-ExcludeCondition] <Object[]>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Copy-DbaPolicyManagement -Source sqlserver2014a -Destination sqlcluster

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

Example: 2
PS C:\> Copy-DbaPolicyManagement -Source sqlserver2014a -Destination sqlcluster -SourceSqlCredential $cred

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

Example: 3
PS C:\> Copy-DbaPolicyManagement -Source sqlserver2014a -Destination sqlcluster -WhatIf

Shows what would happen if the command were executed.

Example: 4
PS C:\> Copy-DbaPolicyManagement -Source sqlserver2014a -Destination sqlcluster -Policy 'xp_cmdshell must be disabled'

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

Required Parameters

-Source

Source SQL Server.You must have sysadmin access and server version must be SQL Server version 2008 or higher.

Alias
Required True
Pipeline false
Default Value
-Destination

Destination Sql Server. You must have sysadmin access and server version must be SQL Server version 2008 or higher.

Alias
Required True
Pipeline false
Default Value

Optional Parameters

-SourceSqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-DestinationSqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Policy

The policy(ies) to process - this list is auto-populated from the server. If unspecified, all policies will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludePolicy

The policy(ies) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-Condition

The condition(s) to process - this list is auto-populated from the server. If unspecified, all conditions will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeCondition

The condition(s) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-Force

If policies exists on destination server, it will be dropped and recreated.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value