The very fact that you are here reading this blog is because you have selected to manage your Azure service using Powreshell. Welcome to the team!!
I assume that you are already have a valid Azure subscription. Powershell 3.0 or higher and have the Windows Azure Powershell modules installed. If you do not have the Azure Powershell modules, you can download the Azure PowerShell module here.
Authenticating with a Certificate
You have to download the .publishsettings file from the Microsoft Azure . You can use the below command:
Get-AzurePublishSettingsFile
This will automatically ask you to select your favourite browser, so you can login to Microsoft Azure website.
Now login with your credentials, that you always do with the Azure Portal
The file that we downloaded is very important and we have to handle it with a lot of care. Any one who can get their hands on this file, will have complete access to resources under that subscription. Microsoft imposes a limit on the total number of management certificates that can be associated with a subscription at a time. The number is 100 at the time of writing this blog. Each time you run the Get-AzurePublishSettingsFile cmdlet, Azure generates a new management certificate.
Importing the .pubishsettings file
The next step is to import the .publishsettings file that we just downloaded. I have saved in “E:\Work\Powershell\scripts”, so I am going to run the Import-AzurePublishSettingsFile cmdlet with the complete file path to the settings file.
Import-AzurePublishSettingsFile "E:\Work\Powershell\scripts\Pay-As-You-Go-9-9-2016-credentials.publishsettings"
As you can see that the cmdlet outputs the subscription information, telling you that the settings are successfully imported.
To double confirm, you can run the Get-AzureSubscription cmdlet.
This cmdlet also tells you, if this subscription is your “Current” / “Default” subscription.
If you have multiple subscriptions, use the Set-AzureSubscription cmdlet to set any azure subscription as “Current” or “Default”.
Also, use the Select-AzureSubscription if you want to switch between subscriptions while working with Powershell.