Type Cast Issue – Cannot convert the Microsoft.WindowsAzure.Commands Storage.AzureStorageContext

Hello EveryBody,

Hope you all are doing good !!!

Issue :

In my last article, we have seen how to resolve an issue with getting Azure Storage Context . After fixing that issue, when we proceed to create the Stored Access Policy using following coad snippet we face another error of Type Cast as showing here.

New-AzureStorageContainerStoredAccessPolicy -Context $ctx4 -Container “kj-container” -Policy “FourDays-rwdl-Access_KJ-Container” -Permission rwdl -StartTime $StartTime -ExpiryTime $EndTime

Figure 1 – Type Cast Issue

Error :

New-AzureStorageContainerStoredAccessPolicy : Cannot bind parameter ‘Context’. Cannot convert the “Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext” value of type
“Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext” to type “Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext”.
At line:4 char:54New-AzureStorageContainerStoredAccessPolicy -Context $ctx4 -Container …CategoryInfo : InvalidArgument: (:) [New-AzureStorag…redAccessPolicy], ParameterBindingException FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.NewAzureStorageContainerStoredAccessPolicyCommand

Solution :

Initially I thought, it is an issue of powershell, because I was using PowerShell 5.1 so I have tested the same coad in PowerShell 7.x and found following different error.

New-AzureStorageContainerStoredAccessPolicy: The ‘New-AzureStorageContainerStoredAccessPolicy’ command was found in the module ‘Azure.Storage’, but the module could not be loaded. For more information, run ‘Import-Module Azure.Storage’.

It means, the command New-AzureStorageContainerStoredAccessPolicy exist under Azure.Storage Module And we are now using Az.Storage module s we need to use relevant command, which exist under Az.Storage module.

Therefore instead of New-AzureStorageContainerStoredAccessPolicy command I used New-AzStorageContainerStoredAccessPolicy command and it works fine and I was able to resolved the type cast issue.

I hope this is informative to you. Please let me know if I missed anything important or if my understanding is not up to the mark.

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.

If you have any suggestion / feedback / doubt, you are most welcome. Stay tuned on Knowledge-Junction, will come up with more such articles.

Thanks for reading 🙂 .

Manas Ranjan Moharana

Around 11+ years of total IT experience and since last 10 years working on almost on all version of SharePoint .Interested in learning and sharing something new to be helthy.

You may also like...

1 Response

  1. May 31, 2021

    […] Next story Type Cast Issue – Cannot convert the Microsoft.WindowsAzure.Commands Storage.AzureS… […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: