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 Site Recovery Azure Site Recovery (ASR) is by far one of the Azure features that I always like to play with. The improvement along the time is above extraordinaire!...
Windows Azure and Office 365 – Getting a fre... In this first article we will go over the process to subscribe on both Office365 and Windows Azure, and after that in our following Tutorials we will ...
Installing Azure CLI on a Mac OS X Microsoft Azure is open for all type of administrators, and if you use a Mac OS X,  you can access the portal using your Safari and also use Azure CLI...
Running PowerShell on Mac OS PowerShell for everyone! In this Tutorial we are going the installation process on Mac OS.SolutionThe first step is to download the .pkg file which is...