Home > Blockchain >  Connect to Azure Storage via Connection String
Connect to Azure Storage via Connection String

Time:07-04

I have an Azure Storage (StorageV2), and I want to connect and upload files via Powershell.

However, I want to use the Connection String (which contains a long secret key). So people without a Microsoft account should be able to use the script.

There is the command Connect-AzAccount, but for this, it seems you need to have a Microsoft account.

So how is it possible to connect and upload just with the Connection String and without having a Microsoft account?

CodePudding user response:

Each Cmdlet in Az.Storage module expects a -Context parameter. You can use New-AzStorageContext Cmdlet to set that context and pass that context to the Cmdlet (e.g. for uploading blob).

If you have the connection string for your storage account, you would create a context like:

$ctx = New-AzStorageContext -ConnectionString "your-storage-account-connection-string"

and use it like the following:

Set-AzStorageBlobContent -Context $ctx ...rest of the parameters
  • Related