New-AzStorageAccountManagementPolicyRule
建立 ManagementPolicy 規則物件,此對象可用於 Set-AzStorageAccountManagementPolicy。
語法
New-AzStorageAccountManagementPolicyRule
[-Name] <String>
[-Disabled]
-Action <PSManagementPolicyActionGroup>
[-Filter <PSManagementPolicyRuleFilter>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
New-AzStorageAccountManagementPolicyRule Cmdlet 會建立 ManagementPolicy 規則物件,此物件可用於 Set-AzStorageAccountManagementPolicy。
範例
範例 1:建立 ManagementPolicy 規則對象,然後將 設定為記憶體帳戶
$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -daysAfterModificationGreaterThan 100
$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToArchive -daysAfterModificationGreaterThan 50 -InputObject $action
$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction TierToCool -daysAfterModificationGreaterThan 30 -InputObject $action
$action = Add-AzStorageAccountManagementPolicyAction -SnapshotAction Delete -daysAfterCreationGreaterThan 100 -InputObject $action
$filter = New-AzStorageAccountManagementPolicyFilter -PrefixMatch blobprefix1,blobprefix2
$rule = New-AzStorageAccountManagementPolicyRule -Name rule1 -Action $action -Filter $filter
$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"
]
}
}
$policy = Set-AzStorageAccountManagementPolicy -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -Rule $rule
此命令會建立 ManagementPolicy 規則物件,其中 ManagementPolicy 動作群組物件包含 4 個動作、ManagementPolicy 規則篩選物件,然後將規則設定為記憶體帳戶。
參數
-Action
定義動作集的物件。 使用 Cmdlet 取得物件 Add-AzureStorageAccountManagementPolicyAction
類型: | PSManagementPolicyActionGroup |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | False |
-DefaultProfile
用於與 Azure 通訊的認證、帳戶、租用戶和訂用帳戶。
類型: | IAzureContextContainer |
別名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Disabled
如果設定規則,則會停用規則。
類型: | SwitchParameter |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Filter
定義篩選集的物件。 使用 Cmdlet 取得物件 New-AzureStorageAccountManagementPolicyFilter
類型: | PSManagementPolicyRuleFilter |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | True |
接受萬用字元: | False |
-Name
規則名稱可以包含任意組合的英數位元。 規則名稱區分大小寫。 它在原則內必須是唯一的。
類型: | String |
Position: | 0 |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
輸入
None