Connect to azure blob storage

Viewed 144

I am using the below powershell script to connect to azure datalake storage gen2 using my credentials for development and after deployment use managed identity credentials.

Code:

try {
        $AzStorageContext = (Connect-AzAccount -Identity).context;
    }
catch{
        $AzStorageContext = (Connect-AzAccount).context;
    }

$AzStorageContext = Set-AzContext -SubscriptionName $AzStorageContext.Subscription -DefaultProfile $AzStorageContext
Get-AzStorageContainer -Name 'MyContainer' -Context $AzStorageContext

The error I run into is

Error:

Get-AzStorageContainer : Cannot bind parameter 'Context'. Cannot convert the "Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext" value of type 
"Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext" to type "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext".
1 Answers

Connecting Azure storage with system-assigned managed identity using Power Shell

$AzureContext = (Connect-AzAccount -Identity).context

$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext

For more information refer this SO thread by VenkateshDodda-MSFT

Related