Usually when I’m writing PowerShell scripts I do it from a development virtual machine with a known environment state. However, yesterday I was trying to do something simple and quick and was writing it on my everyday laptop.

My script was using Windows Management Framework 5.0 and I was creating a new burn environment in AzureRM. I was authenticated and could query and enumerate most of my AzureRM environment, however I was getting erroneous responses on some cmdlets and was unable to create a new resource group. Essentially whenever I tried to perform anything of value to what I was trying to achieve PowerShell would return ”Run Login-AzureRmAccount to login.”

I was authenticated and all looks as it should.

LoggedIn

Query ARM RG and get the error, ”Run Login-AzureRmAccount to login.”

LoginError

I started digging to find out what my environment was looking like. Did I have WMF5 installed?  $PSVersionTable showed I did and all looked as it should.

PSEnv

What modules did I have installed? Get-InstalledModule | Out-GridView

PSModules

Lots of differing versions is what I saw *Note: screenshot above is after resolving my issue.

So what fixed my issue? I ran Update-Module and watched PowerShell update my modules and get my environment back into spec. A restart of my laptop and back in action.

What caused my issue? I’m thinking I updated an individual module at some point and dependencies were missed.

Hope this helps someone else and saves some of those “this should just be working, why isn’t it” moments.

 

Category:
Azure Platform, PowerShell
Tags:
,

Join the conversation! 5 Comments

  1. I have had the same error when running the commands in a powershell window. I had to launch the commands in PowerShell ISE to overcome it in the end. I will give this a go if the error comes back. Thanks

  2. tried all these mentioned above and looked at other websites but no luck and this shit doesn’t work and there’s no simple answer for this, i am on windows 2016 std. server and using PS ver 5.1.14393.953

    anymore help on this to get it working. many thx in advance

  3. Hi, tried this solution, but with no luck. It led me to another fix by reinstalling everything. I wrote anouther post regarding that soluton: http://tomow.de/dev/run-login-azurermaccount-to-login-in-azurerm-when-already-logged-in-with-powershell/

  4. “Most likely this is caused by multiple versions of Azure PowerShell installed on the machine. You can find this out with

    Get-Module -ListAvailable

    If azure powershell modules show up anywhere other than in %progranfiles (x86)%\Microsoft SDKs\Azure\PowerShell, then have the customer remove them.”

    https://github.com/Azure/azure-powershell/issues/2688

Comments are closed.