Showing posts with label Import-AzurePublishSettingsFile. Show all posts
Showing posts with label Import-AzurePublishSettingsFile. Show all posts

Wednesday, February 26, 2014

Troubleshooting Windows Azure authentication in PowerShell.


Hi, in my previous post I have published an article on how to connect with the Windows Azure using PowerShell. 
If you remember I had mentioned two ways to connect to the Windows Azure using PowerShell. The first is using Azure AD authentication and second one is using publishing Certificate.
Yesterday we imported the certificate to my machine and it was working well. But today when I tried to connect to my Azure account using PowerShell and run few Azure PowerShell cmdlet, I am getting the below error.

clip_image002

And getting the same error on the “Windows Azure PowerShell Console” too.
clip_image004

So I was wondering what might be the issue is, as I was working well yesterday. And I just remember that. Yesterday Before using the certificate methods to login, we used a windows Azure Authentication to login and these login was valid for 12 hours, that’s why we able to login and able to run Azure PowerShell cmdlets yesterday.

Solution

After few tries, I manage to connect with my Windows Azure account using previously installed certificated.
One of the he solutions is:  Try running PowerShell Console as Administrator
If you are facing problem in running windows  Azure PowerShell cmdlets using certificates, try running  PowerShell as administrator and then run Azure cmdlets.  
I run the PowerShell as administrator and imported Azure module and after that I am successfully able to run windows Azure PowerShell cmdlets.
clip_image006

See you in my next blog post.
Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Tuesday, February 25, 2014

Part-2: Azure and PowerShell: Connect to Windows Azure using PowerShell

 

Part-1 : Getting Started With Windows Azure And PowerShell

In my previous post, I have posted about getting started with Windows Azure and PowerShell.

We have already downloaded and installed the Window Azure PowerShell module.

Today we will connect to our Windows Azure subscription with PowerShell, so that we can run Windows Azure PowerShell cmdlets and start automating stuff.

Connect with Windows Azure

There are two ways to connect to the Windows Azure subscription,

1.       Windows Azure AD method.

a.       We can connect to window Azure using Ad method by providing our Azure subscriptions username and password but the main issue with Windows Azure AD authentication method is, that saved credentials are expired after 12 hours and after expiration we need to login in again. This is not a good choice when we want to automate tasks using PowerShell.

2.       Using Certificates

a.       When we use certificated method to login, they are valid until the subscription in available and certificates are valid. This is recommended option for automation of the task and for long running scripts.

Connect using Azure AD Method

To connect to Windows Azure using AD method, do the following.

Open Windows Azure PowerShell {or Import-Module Azure in your current PowerShell console.}

clip_image001  OR  clip_image003

Run the Add-AzureAccount cmdlet

This will open a “Sign in to Windows Azure” window.

Provide your windows Azure’s subscription email address and click on continue.

clip_image005

 

Or might be you will see the below asking for your username and password, provide your details {which you use to login to https://manage.windowsazure.com and click on Sign in.

clip_image007

 

Once is account is verified, you will be return back to the PowerShell console.

clip_image008

 

For testing let’s run the Get-AzureAccount cmdlet and see if it return anything.

Get-AzureAccount

clip_image010

 

Seeming working J and you are successfully connected to the cloud.

 

Connect using Certificate Method.

To connect to Windows Azure using PowerShell, we need to get our certificate first. To get the certificate please do the following.

1.       Open Windows Azure PowerShell console, or import the Windows Azure PowerShell module to your current PowerShell profile.

2.       Run the Get-AzurePublishSettingsFile cmdlet

3.        

4.       clip_image011

5.        

6.       This cmdlet redirect to the Windows Azure login page and please provide your Windows Azure login credential to login to the portal.

7.       Once you successfully login, you will see the below page and your certificated will download automatically.

8.       clip_image013

9.       Now we have to import the publish setting file.

10.   Now run  Import-AzurePublishSettingsFile  cmdlet and provide the path to the certificate which we have just downloaded.

11.   clip_image015

12.   Once you run the above cmdlet. Delete your certificate file which we have just downloaded.

 

For testing let’s run Get-AzureSubscription cmdlet. And everything is working perfectly.

clip_image016

 

That’s all for now. See you in my next blog post.

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021