Question

Marcel Balcarek on Mon, 10 Apr 2017 21:41:59


Hello, 

I have researched this and similar issues, but have not found an answer.

I run the following commands. They work on one machine (with earlier versions of Azure-RM) but not on two other machines (with the latest versions of Azure-Rm 3.8.0).  Even though Login-AzureRmAccount  works, Get-AzureRmStorageAccount fails with error:

Get-AzureRmStorageAccount : Your Azure credentials have not been set up or have expired, please run Login-AzureRMAccount to set up your Azure credentials.

    $AzureUsername = 'Automation@myco.onmicrosoft.com';
    $AzurePassword = ConvertTo-SecureString "abcd" -AsPlainText –Force
    $AzureCredential = New-Object -TypeName pscredential -ArgumentList $AzureUsername, $AzurePassword;
    Login-AzureRmAccount –Credential $AzureCredential
    Get-AzureRmSubscription -SubscriptionId "guid-fbcb-438a-ba96-aa1bc3527393" | Select-AzureRmSubscription
    $storageAccount = Get-AzureRmStorageAccount -Name "site2sto05" -ResourceGroupName "site2-rg01"

FYI: We only have one subscription. Seems like the latest version has some sort of mismatch?

Installation:

Save-Module -Name AzureRM -Path D:\PowerShell\GitHub

Install-Module -NameAzureRM -AllowClobber -RequiredVersion 3.8.0

Non-working version:

$PSVersionTable.PSVersion  is 5.1 14409 1005

(Get-Module-ListAvailable|Where-Object{ $_.Name -eq'Azure'}) `

|SelectVersion,Name,Author,PowerShellVersion  |Format-List; is 3.7.0

Working versions:

5      1      14393  953   and 2.1.0

Q How do I resolve this issue? If I need to revert, how do I do that?

Thank you


Marcel






Replies

PRADEEP CHEEKATLA on Tue, 11 Apr 2017 14:18:11


The error " Your Azure credentials have not been set up or have expired - works on one machine " indicates that your access token is expired and Windows PowerShell cannot access your Azure account.

To restore access to your account, run Login-AzureRmAccount or Add-AzureRmAccount.

If the issue persists, remove all associated environments, subscriptions, and accounts. And login again.

Marcel Balcarek on Tue, 11 Apr 2017 14:51:07


Pradeep, thank you for responding.

I have done all of that - the code (see above) uses Login-AzureRmAccount just prior to the error. Like I said, we have one subscription, which I explicitly select in the code.  I have even run Remove-Azure Account, just in case. Get-AzureAccount is blank.

I suspect this error is specific to Get-AzureRmStorageAccount . Other commands work ok, such as Get-AzureRmContext ... UPDATE 5/52017: Get-AzureRmVM has the same error.

The installations of AzureRM are new on these 2 machines where it does not work (Win server 2012 R2). It works ok on my Win 10 dev machine with older versions of AzureRM.


Marcel



PRADEEP CHEEKATLA on Tue, 11 Apr 2017 18:50:33


I would recommend you check whether you have installed latest version of PowerShell on your system.

Azure PowerShell Download

After installing PowerShell, run as administrator and install Azure modules by using following cmdlet:

Install-Module AzureRM

Log in to Azure by using the following cmdlet:

Login-AzureRmAccount    OR       Add-AzureRmAccount

For more information, see “Getting started with Azure PowerShell”.

Marcel Balcarek on Tue, 11 Apr 2017 21:25:19


Pradeep,

As I stated in the original post - I have the latest version installed.

PRADEEP CHEEKATLA on Wed, 12 Apr 2017 13:44:27


I would suggest you to delete all the PowerShell files from the Azure folder and then do a fresh installation.

Location: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell

Marcel Balcarek on Wed, 12 Apr 2017 21:36:50


WARNING: don't do steps 1 and 2 if you have Azure Service Manager modules installed, as it will delete those too.

  1. I ran: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\RemoveGalleryModules.ps1
  2. I deleted the folder C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell
  3. I rebooted
  4. I ran the following 2 commands to install AzureRM

Save-Module -Name AzureRM -Path D:\PowerShell\GitHub 
Install-Module -Name AzureRM #-AllowClobber -RequiredVersion 3.8.0

I rebooted.

I still have the issue. This is a Windows Server 2008 R2 SP1 server, latest updates applied.

See attachment.


Same code works from a different machine. (Win10)

Marcel




J R Halasz on Thu, 26 Apr 2018 16:08:59


I'm having the same issue. 

Did you ever get this figured out?

Marcel Balcarek on Thu, 26 Apr 2018 19:35:00


J R,

No. I continue to run it from a windows 10 machine, where it works. Let me know if you find a  fix! Does not work from our 2012 R2 Server.

Sadiqh Ahmed on Fri, 27 Apr 2018 16:18:51


This is very common when multiple versions of the AzureRM modules exist on the machine.

- You should clean up ALL directories in C:\Program Files\WindowsPowerShell\Modules that begin with AzureRM
- Considering the modules you were installing were 3.8, you should now use the latest version of the AzureRM modules which is 5.7 from the gallery.

Also you should ensure the 2008R2 machine has at least PowerShell version 3.0 installed, however recommended is PowerShell 5.1.

-----------------------------------------------------------------------------------------------------------------------------------
If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here