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".