Search code examples
powershellazurepowershell-cmdlet

Still requiring Login-RmAzureAccount even after importing PublishSettings in Azure


I am attempting to login to an Azure account through a PowerShell script by means of making use of a publishsettings file; However, I am still finding that it is requiring me to login to my account using Login-AzureRmAccount, regardless of having those credentials.

My step-by step looks something like this:

Clear out all accounts that may be available: Get-AzureAccount | ForEach-Object { Remove-AzureAccount $_.ID -Force }

Download the PublishSettings file: Import-AzurePublishSettingsFile –PublishSettingsFile $PublishSettingsFileNameWithPath

Select the Azure subscription using the subscription ID: Select-AzureRMSubscription -SubscriptionId $SubscriptionId

And finally, create a new resource group in the subscription before deploying it: New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force 2>> .\errorCIMS_RG.txt | Out-File .\rgDetailsCIMS_RG.txt

However, this is when an error is thrown: Run Login-AzureRmAccount to login.

Assuming I have the PublishSettings file, and it hasnt expired, why would this be giving back an error?


Solution

  • As Mihail said, we should check Azure PowerShell version first, and install the latest version.
    We can run this command to list Azure PowerShell version:
    Get-Module -ListAvailable -Name Azure -Refresh

    By the way, Import-AzurePublishSettingsFile work for ASM, New-AzureRmResourceGroup is ARM command, so if you want to create resource group, you should Login-AzureRmAccount first.

    Note:

    The AzureResourceManager module does not support publish settings files.

    More information about Import-AzurePublishSettingsFile, please refer to this link.