Edit

Edit-AzDataProtectionPolicyRetentionRuleClientObject

Adds or removes Retention Rule to an existing backup policy.

Syntax

RemoveRetention (Default)

Edit-AzDataProtectionPolicyRetentionRuleClientObject
    -Policy <IBackupPolicy>
    -Name <RetentionRuleName>
    [-RemoveRule]
    [<CommonParameters>]

AddRetention

Edit-AzDataProtectionPolicyRetentionRuleClientObject
    -Policy <IBackupPolicy>
    -Name <RetentionRuleName>
    -IsDefault <Boolean>
    -LifeCycles <ISourceLifeCycle[]>
    [-OverwriteLifeCycle <Boolean>]
    [<CommonParameters>]

Description

Adds or removes Retention Rule to an existing backup policy.

Examples

Example 1: Add Weekly Retention Rule

$pol = Get-AzDataProtectionPolicyTemplate
$lifecycle = New-AzDataProtectionRetentionLifeCycleClientObject -SourceDataStore OperationalStore -SourceRetentionDurationType Weeks -SourceRetentionDurationCount 5
Edit-AzDataProtectionPolicyRetentionRuleClientObject -Policy $pol -Name Weekly -LifeCycles $lifecycle -IsDefault $false
DatasourceType            ObjectType
--------------            ----------
{Microsoft.Compute/disks} BackupPolicy

The first command gets the default policy template. The second command creates a weekly lifecycle object. The third command adds a weekly retention rule to the default policy.

Example 2: Remove Weekly Retention Rule

Edit-AzDataProtectionPolicyRetentionRuleClientObject -Policy $pol -Name Weekly -RemoveRule
DatasourceType            ObjectType
--------------            ----------
{Microsoft.Compute/disks} BackupPolicy

This command removes weekly retention rule if it exists in given backup policy.

Example 3: Add an OperationalStore retention rule to an AzureBlob policy

$pol = Get-AzDataProtectionPolicyTemplate -DatasourceType AzureBlob
$opLifecycle = New-AzDataProtectionRetentionLifeCycleClientObject -SourceDataStore OperationalStore -SourceRetentionDurationType Days -SourceRetentionDurationCount 30
Edit-AzDataProtectionPolicyRetentionRuleClientObject -Policy $pol -Name Default_OperationalStore -LifeCycles $opLifecycle -IsDefault $true
DatasourceType                                  ObjectType
--------------                                  ----------
{Microsoft.Storage/storageAccounts/blobServices} BackupPolicy

For AzureBlob, OperationalStore retention rules must be named Default_OperationalStore. The rule is added additively — the existing Default (VaultStore) retention rule on the policy template is preserved. Passing -Name Default with an OperationalStore lifecycle is rejected by validation.

Note: -OverwriteLifeCycle is deprecated and will be removed in an upcoming release. Setting -OverwriteLifeCycle $false blocks updating an existing retention rule; when $true or omitted, the existing rule's lifecycles are replaced in place — the default behavior once this parameter is removed.

Parameters

-IsDefault

Specifies if retention rule is default retention rule.

Parameter properties

Type:Boolean
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddRetention
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-LifeCycles

Life cycles associated with the retention rule.

Parameter properties

Type:

ISourceLifeCycle[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddRetention
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

Retention Rule Name. Note: "Default" retention rules cannot be removed, regardless of lifecycle.

Parameter properties

Type:RetentionRuleName
Default value:None
Accepted values:Default, Daily, Weekly, Monthly, Yearly, Default_OperationalStore
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-OverwriteLifeCycle

[Deprecated] Optional; this parameter will be removed in an upcoming release. Setting -OverwriteLifeCycle $false blocks updating an existing retention rule; when $true or omitted, the existing rule's lifecycles are replaced in place — the default behavior once this parameter is removed.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddRetention
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Policy

Backup Policy Object

Parameter properties

Type:IBackupPolicy
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-RemoveRule

Specifies whether to remove the retention rule.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

RemoveRetention
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Outputs

IBackupPolicy

Notes

  • "Default" retention rules cannot be removed, regardless of lifecycle. -RemoveRule -Name Default throws Removing Default Retention Rule is not allowed. Please try again with different rule name.
  • -OverwriteLifeCycle is deprecated and will be removed in an upcoming release. Setting -OverwriteLifeCycle $false blocks updating an existing retention rule; when $true or omitted, the existing rule's lifecycles are replaced in place — the default behavior once this parameter is removed.