FIX: Import module failed New-AzureStorageContext is not recognized Az

Importing of module failed. –> Azure Automation.

I was working on a function that would automatically update outdated modules in Azure Automation. I used my own Microsoft Graph module as a test.

During the automatic upload I got a message that Automation was importing the module, but after a while the status was set to Failed and I saw the following error:

Error importing the module Microsoft.Graph.API. Import failed with the following error: System.Management.Automation.CommandNotFoundException: The term 'New-AzureStorageContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Okay, I can understand that it doesn’t work through PowerShell, but if I try through GUI it wouldn’t work either.


Did you happen to tinker with the global modules? And does this happen to be the Azure.Storage module?
If you have done this, the status of this module is probably set to ‘Failed’ as shown in the screenshot below.

FIX: Importing module in Azure Automation failed 'New-AzureStorageContext' is not recognized.
FIX: Importing module in Azure Automation failed ‘New-AzureStorageContext’ is not recognized.

This module contains the New-AzureStorageContext cmdlet. This is used to upload modules. Hence, it is also pre-configured and ‘IsGlobal -eq True’, if you have not updated or modified the module.


Importing Azure.Storage from the PSGallery runs in to the same error.

You do not have to reinstall the Azure.Storage module. I have already tried that and it leads to the same error message:

Error importing the module Azure.Storage. Import failed with the following error: System.Management.Automation.CommandNotFoundException: The term 'New-AzureStorageContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

It’s actually much easier. When you remove the module from Azure Automation you see the following message: ‘If there is a global module version, this will restore the global module’.

FIX: Importing module in Azure Automation failed 'New-AzureStorageContext' is not recognized.
FIX: Importing module in Azure Automation failed ‘New-AzureStorageContext’ is not recognized.

The window probably shows that it is not a global module, but that is because you have probably made an update.

You can press the ‘Delete’ button and then restore it to the global module, as you can see in the screenshot below.

FIX: Importing module in Azure Automation failed 'New-AzureStorageContext' is not recognized.
FIX: Importing module in Azure Automation failed ‘New-AzureStorageContext’ is not recognized.

After that I was able to update and install modules in Azure Automation.
Also via PowerShell…

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

Leave a Reply

Your email address will not be published. Required fields are marked *