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.

image

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.

image

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.

image

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 ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).

Related Post

Azure AD Connect–Forcing synchronization usi... If you are using Azure AD Connect and want to force a synchronization using PowerShell, stick around and we are going over the process.  Solutio...
Azure Backup – Part 3 – Backup Virtual Machines... On the first post (see here), I explained how the Azure backup works. On this post, I’m explaining how to backup Virtual Machines with Azure Backup. ...
Containers on Azure – Part 2 On the previous post (see here), I talked about the concept of Containers, Azure Container Service and Azure Service Fabric. Now that you know the con...
How to install Azure Storage Explorer on macOS Microsoft Azure is a multi-platform solution, and for the IT Pro we can chose which platform we want to use to manage the servicem including macOS, Li...