Create replication policy on destination account

Garth Meyer 0 Reputation points
2024-05-19T09:44:23.3066667+00:00

I'm trying to run the below command in powershell

$destPolicy = Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgName -StorageAccountName $destAccountName -PolicyId default -SourceAccount $srcAccountName -Rule $rule1,$rule2

but i receive the below error

Set-AzStorageObjectReplicationPolicy : Operation returned an invalid status code 'BadRequest'

At line:1 char:15

  • ... estPolicy = Set-AzStorageObjectReplicationPolicy -ResourceGroupName $ ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [Set-AzStorageObjectReplicationPolicy], ErrorResponseException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Management.Storage.RSetAzureStorageAccountObjectReplicationPolicyCommand
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,782 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,418 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 14,580 Reputation points MVP
    2024-05-19T11:54:04.25+00:00

    The error message "Operation returned an invalid status code 'BadRequest'" indicates that there was an issue with the request sent to the Azure Storage service. In this case, it seems that the request made by the Set-AzStorageObjectReplicationPolicy cmdlet was not valid, resulting in a "BadRequest" response from the Azure service.

    To troubleshoot this issue, you can try the following steps:

    1. Verify Parameters: Double-check the parameters passed to the Set-AzStorageObjectReplicationPolicy cmdlet. Ensure that all required parameters are provided and correctly formatted, including resource group name, storage account names, policy ID, and replication rules.
    2. Check Account Permissions: Ensure that the account used to execute the PowerShell command has sufficient permissions to perform the operation. The account should have the necessary permissions to manage storage accounts and configure object replication policies.
    3. Review Rule Configuration: Review the configuration of the replication rules ($rule1 and $rule2) to ensure they are correctly defined and comply with Azure Storage replication requirements.

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

  2. Amrinder Singh 3,645 Reputation points Microsoft Employee
    2024-05-20T12:27:01.7666667+00:00

    Hi Garth Meyer - Thanks for reaching out.

    I tried the below sample script to create 2 rules was able to configure the policy on the destination account correctly.

    $rgName = "ResourceGroupName"

    $srcAccountName = "Source Account Name"

    $destAccountName = "Destination Account Name"

    $srcContainerName1 = "Source Container 1"

    $destContainerName1 = "Destination Container 1"

    $srcContainerName2 = "Source Container 2"

    $destContainerName2 = "Destination Container 2"

    Define replication rules for each container.

    $rule1 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName1 `

    -DestinationContainer $destContainerName1 `
    

    $rule2 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName2 `

    -DestinationContainer $destContainerName2  `
    

    Create the replication policy on the destination account.

    $destPolicy = Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgName `

    -StorageAccountName $destAccountName `
    
    -PolicyId default `
    
    -SourceAccount $srcAccountName `
    
    -Rule $rule1,$rule2
    

    Reference Link:

    https://learn.microsoft.com/en-us/azure/storage/blobs/object-replication-configure?tabs=powershell#configure-object-replication-with-access-to-both-storage-accounts

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.