Hi everyone, I hope you’re staying healthy. I want to show you how to copy a blob between two Azure storage accounts in the same Azure subscription using PowerShell in this post.

Prerequisites

  • Two storage accounts will be used in the following example. You can use two existing storage accounts, or you can create new ones. If you want to know how to create a storage account using PowerShell, check out this link.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties.

Source Storage Account

We first define the variables for the source storage account. In the $ blobName variable, you specify the file’s name that will be copied to the other storage account.

Destination Storage Account

As in the case of the source account, we define the variables for the destination storage account.

Storage Account Keys

To obtain the key for each of the storage accounts involved. It would help if you used the Get-AzStorageAccountKey cmdlet with the following syntax.

Storage Account Context

Using the New-AzStorageContext cmdlet, you set the context for the source and destination storage account.

Destination Container (optional)

This step is optional, and you should use the following command if the container in the destination account does not exist yet. If you want to know more about how to Managing containers and blobs, check out this link.

Start the copy process

Finally, to start the blob copy process between the two storage account, you should use the Start-AzStorageBlobCopy cmdlet with the following syntax. If you want the file in the destination directory to have a different name than the source file, you should change the value of the -DestBlob parameter.

The duration of the copy process will depend on the size of the blob.

Check the copy status

If you want to monitor the copy process, you should use the Get-AzStorageBlobCopyState cmdlet as follows.

copy blob

Thanks for reading my post. I hope you find it helpful.

If you want to know more about the Azure Storage Cmdlets, check out this link.