MethodNotAllowed when using Backup-AzureKeyVaultSecret

Share this:

I’ve been working with Azure Automation in the last few days, and during the creation of the code I was using PowerShell ISE to backup and restore Azure Key Vault secrets and keys between Azure Key Vaults.

When I moved my code to Azure Automation, I noticed the error Operation returned an invalid status code only when executing the Backup-AzureKeyVaultSecret cmdlet. Initially, I thought was something related to permissions, but after some troubleshooting I removed the permission from the picture.


The issue was related to modules, when compared the modules that I had in my machine against the Hybrid Worker VM, I noticed that Azure Key Vault module 4.3.0 has no issues running the Backup-AzureKeyVaultSecret , however the same cmdlet fails when running on the latest version 5.0.0.

If that is your case, I recommend first comparing the modules loaded, by running Get-Module, we can always check all modules using Get-Module –ListAvailable which will provide the output of all modules and their respective folder.

In order to install a specific module version, we can use the following cmdlet:

Install-Module AzureRM.KeyVault –MaximumVersion 4.3.0 –Force

In my scenario, the AzureRM.KeyVault had to be 4.3.0, and after installing the module, we have a couple of ways to remove non-required modules.

The first method is going to the folder where the module has been installed, and remove the folder.


My preferred method is using PowerShell, we can use Uninstall-Module and combine with –RequiredVersion to remove the specific module. The process to list the existent modules, remove and list them again is shown in the image below.


Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at,, and Anderson (Portuguese).

Related Post

Automating the process to join a server to a domai... In this Tutorial we are going to optimize a simple task that in larger environments may take some time from the service desk/operations team which is ...
Windows Azure and Office365 – Installing the Synch... In order to synchronize our on-premises Active Directory with Windows Azure Active Directory (WAAD) we can use a tool called Windows Azure Active Dire...
Removing Azure Active Directory users using Azure ... Cloud Shell is one of the new features in Azure Portal, and it is accessible from virtually any browser and even from Azure App. In this Tutorial, we ...
Getting the number of mailboxes per database in yo... How to create a single line PowerShell to retrieve the number of mailboxes per mailbox database in your organization. I was asked about that number in...