Monday, April 20, 2015

Use certificate for authentication on Microsoft Azure PowerShell environment

By default, we need to provide the credential by performing "Add-AzureAccount" before we perform other cmdlets to configure the current Azure subscription by PowerShell. Even though you configured the default Azure subscription, we still need to perform "Add-AzureAccount" before performing Azure cmdlets. If not, you find the following error message.

Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your Azure credentials.


Microsoft Azure provided another method for authentication on Azure PowerShell module. We can use a certificate for authentication. To obtain a certificate, we can perform "Get-AzurePublishSettingsFile". I'm going to obtain a certificate from my Azure subscription.

Prerequisites
  • Install and import Azure PowerShell module

Lab
1. Log in your Microsoft Azure subscription with the default browser.


There is no certificate under "Management Certificates".

2. Launch PowerShell with Azure module.
3. Perform "Get-AzurePublishSettingsFile".


Then, your browser will redirect to the web page to download a certificate.


4. Click "Save" to save the credential file into the computer.


You can copy the file to a computer which you want to use to manage Azure.

5. Back to Azure Portal, there is a certificate under "Management Certificates".


6. Back to PowerShell console, perform "Import-AzurePublishSettingsFile -PublishSettingsFile <credential file location>" to import the certificate to the user certificate store in this computer.


You can find the certificate under the user certificate store.


Remark: For security reason, please delete the credential file after you imported the certificate to the computer.

Test result
1. Perform "Get-AzureAccount".


I connected to my Azure subscription by this certificate.

2. Perform "Get-AzureVNetConfig".


Eventually, we don't need to perform "Add-AzureAccount" to provide credential before we perform other cmdlets to configure the current Azure subscription.

Reference:
How to install and configure Azure PowerShell

Get-AzurePublishSettingsFile

Import-AzurePublishSettingsFile

This posting is provided “AS IS” with no warranties, and confers no rights!

No comments:

Post a Comment