locked
Copying only container name from one storage account to another RRS feed

  • Question

  • Team,

    I'm copying container name from one storage account to another storage account. Below is the script which i used to make sure only the container which is not present should be created and rest of the one which are present in the destination should be skipped.

    Can anyone know if I'm doing it in right way?

    $storageAccountContext = New-AzureStorageContext -StorageAccountName "copyblob" -StorageAccountKey "xyz"
    $Destinationcontext = New-AzureStorageContext -StorageAccountName 'digitalsignageproduct' -StorageAccountKey 'abc'
    
    $Variable_A = Get-AzureStorageContainer -Context $storageAccountContext 
    $Variable_B = Get-AzureStorageContainer -Context $Destinationcontext
    $Container_to_be_created = Compare-Object -ReferenceObject $Variable_A.name -DifferenceObject $Variable_B.name
    $Container_to_be_created | Select-object -Property Inputobject | ForEach-object { New-AzureStorageContainer -Name $_.Inputobject -Context $Destinationcontext }
    

    Friday, August 10, 2018 1:03 PM

Answers

  • Yes. You are on the right path. I can do the repro on the same and got the expected result.

    --------------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here

    • Proposed as answer by Sandeep BR Friday, August 10, 2018 6:21 PM
    • Marked as answer by Qureshi Aquib Friday, August 31, 2018 4:27 AM
    Friday, August 10, 2018 6:21 PM

All replies

  • Yes. You are on the right path. I can do the repro on the same and got the expected result.

    --------------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here

    • Proposed as answer by Sandeep BR Friday, August 10, 2018 6:21 PM
    • Marked as answer by Qureshi Aquib Friday, August 31, 2018 4:27 AM
    Friday, August 10, 2018 6:21 PM
  • Sandeep,

    Thanks for trying to repro. I know it works. Just wanted to know if my script is efficient or there is some other way to achieve this? what would you do if you wanted to achieve the storage container creation to another storage account.

    Sunday, August 12, 2018 6:04 PM
  • PowerShell coding is the best option to achieve this scenario. Using customer PowerShell script, we can achieve this kind of scenarios.

    --------------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here

    • Proposed as answer by Sandeep BR Thursday, August 16, 2018 8:21 PM
    Thursday, August 16, 2018 8:21 PM
  • Just checking in to see if the above suggestions helped or you need further assistance on this issue.

    Saturday, August 18, 2018 7:20 PM