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

PowerShell Script to fix Exchange Server 2013 Secu... I wrote the following PowerShell script to help fixing the issue reported by Microsoft Exchange Team (http://blogs.technet.com/b/exchange/archive/2013...
Containers on Azure – Part 1 In the last decade, hardware virtualization has drastically changed the IT landscape. One of many consequences of this trend is the emergence of cloud...
How to move your workloads to Azure When integrating your on-premises environment with Azure, you might want to use the lift-and-shift approach to migrate some of your existing workloads...
Top 5 of the Week: Week of May 8th Folks, Here are the top 5 IT news for this week. Quick guide to Windows 10 training and certification for IT pros https://blogs.technet...