New-AzStorageAccountManagementPolicyRule

Creates a ManagementPolicy rule object, which can be used in Set-AzStorageAccountManagementPolicy.

Syntax

New-AzStorageAccountManagementPolicyRule
   [-Name] <String>
   [-Disabled]
   -Action <PSManagementPolicyActionGroup>
   [-Filter <PSManagementPolicyRuleFilter>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The New-AzStorageAccountManagementPolicyRule cmdlet creates a ManagementPolicy rule object, which can be used in Set-AzStorageAccountManagementPolicy.

Examples

Example 1: Creates a ManagementPolicy rule object, then set to a Storage Account

PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -daysAfterModificationGreaterThan 100
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToArchive -daysAfterModificationGreaterThan 50  -InputObject $action
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToCool -daysAfterModificationGreaterThan 30 -InputObject $action
PS C:\>$action = Add-AzStorageAccountManagementPolicyAction -SnapshotAction Delete -daysAfterCreationGreaterThan 100 -InputObject $action

PS C:\>$filter = New-AzStorageAccountManagementPolicyFilter -PrefixMatch blobprefix1,blobprefix2

PS C:\>$rule = New-AzStorageAccountManagementPolicyRule -Name rule1 -Action $action -Filter $filter
PS C:\>$rule

Enabled    : True
Name       : rule1
Definition : {
                 "Actions":  {
                                 "BaseBlob":  {
                                                  "TierToCool":  {
                                                                     "DaysAfterModificationGreaterThan":  30
                                                                 },
                                                  "TierToArchive":  {
                                                                        "DaysAfterModificationGreaterThan":  50
                                                                    },
                                                  "Delete":  {
                                                                 "DaysAfterModificationGreaterThan":  100
                                                             }
                                              },
                                 "Snapshot":  {
                                                  "Delete":  {
                                                                 "DaysAfterCreationGreaterThan":  100
                                                             }
                                              }
                             },
                 "Filters":  {
                                 "PrefixMatch":  [
                                                     "blobprefix1",
                                                     "blobprefix2"
                                                 ],
                                 "BlobTypes":  [
                                                   "blockBlob"
                                               ]
                             }
             }

PS C:\>$policy = Set-AzStorageAccountManagementPolicy -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -Rule $rule

This command create a ManagementPolicy rule object, with a ManagementPolicy action group object contains 4 actions, a ManagementPolicy rule filter object, then set the rule to a Storage Account.

Parameters

-Action

An object that defines the action set. Get the Object with cmdlet Add-AzureStorageAccountManagementPolicyAction

Type:Microsoft.Azure.Commands.Management.Storage.Models.PSManagementPolicyActionGroup
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Disabled

The rule is disabled if set it.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Filter

An object that defines the filter set. Get the Object with cmdlet New-AzureStorageAccountManagementPolicyFilter

Type:Microsoft.Azure.Commands.Management.Storage.Models.PSManagementPolicyRuleFilter
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Name

A rule name can contain any combination of alpha numeric characters. Rule name is case-sensitive. It must be unique within a policy.

Type:String
Position:0
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

Microsoft.Azure.Commands.Management.Storage.Models.PSManagementPolicyRule