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.


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

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.


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.

See you in my next blog post.
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.



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



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



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




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


4.       clip_image011


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.



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


Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Part-1: Azure and PowerShell: Getting Started with Windows Azure and PowerShell


After publishing PowerShell tutorial series on “PowerShell and Event Viewer,” “PowerShell and DHCP Server”, I am going to start a new series on “PowerShell and Windows Azure”.

What is windows Azure?

Windows Azure is an open and flexible cloud platform that enables you to quickly build, deploy and manage applications across a global network of Microsoft-managed datacentres. You can build applications using any language, tool or framework. And you can integrate your public cloud applications with your existing IT environment. {Source}.

In windows Azure, you can create a virtual machines, mobile apps, online Active Directory, websites, SQL databases and lots of other things on cloud.  

Windows Azure is awesome! You can create website, mobile app backend, SQL database, in just few clicks, Imagine creating a fully functional virtual machine in a few clicks of mouse buttons.

 It’s amazingly fast and very easy to do.

Windows Azure is a revolutionary product and in coming time Windows Azure will change a whole IT eco system. Imagine all of your Servers in cloud and all best engineers from Microsoft are taking care of it and you don’t have to worry to patch them, keep them updated and worried about their backups.

You can also signup for windows Azure one month free trial from this link:




Windows Azure supports PowerShell and that’s open a wide range of possibilities of automation, reporting.  We can use PowerShell to automate the Azure supported tasks.

Download and Install Windows Azure PowerShell Module

To connect PowerShell and Window Azure, We have to install Microsoft Windows Azure PowerShell module first, you can download the module from this link.

This will download a file with a  name something like “WindowsAzurePowerShell.3f.3f.3fnew.exe

Double click on the file and click on Install.


For now, keep the all setting as it as and click on “I accept”



It will start installing the Windows Azure PowerShell module and supported applications.





Once all application are installed click on “Finish”



Testing Windows Azure PowerShell Module

On your Windows 8 , you can search for windows Azure Powershell and you will find a PowerShell  console dedicated for Windows Azure only.





And if you want to import a Windows Azure module in to your PowerShell console or IDE, you can use Import-module cmdlet for it.

Import-Module Azure


That’s all for today and in our next blog post we will discuss how to connect with PowerShell and Windows Azure.



Amanclip_image017 clip_image018 clip_image019 clip_image020  clip_image021



Saturday, February 22, 2014

PowerShell and GUI : Checkbox element


Checkbox are very useful element in GUI’s.
When you have to provide options to the user, like, if we want to enable “Active Directory” user account, or disable it, or option of creating email addresses while creating accounts etc.
Checkbox has two major properties, either they can be checked/ticked, or not checked/ticked.
If checkbox is checked / ticked that means it is True ($true).
If checkbox is not checked / ticked that meant it is False ($false).
We can write our logic based on these two properties. We can write that , if checkbox’s checked value is true then do this action and if the checkbox’s checked value is false do this.

Let’s see it in action

Open your favourite PowerShell GUI creator, in my case “PowerShell Studio 2012”.
Create a new form and add these three elements to the form.
1.       Label          clip_image002
2.       Button       clip_image003
3.       Checkbox  clip_image004

You form should be look like this.

Now we are going to implement the following logic.
 If we ticked the checkbox and click on button, our label text will be changed to “Check box is checked.”, and when we un-tick the checkbox and press the button, our text of the label will say “Checkbox is not checked”.
Now double click on our button and it will create a “Mouse Click” event {which we have covered in my past blog post } and add the  below code there.
$checkbox1 is our Checkbox
$button1 is our Button
$label1 is our label

       if ( $checkbox1.Checked -eq $true )
                     $label1.Text = "Checkbox is checked."
                     $label1.ForeColor = 'Green'
                     $label1.Text = "Checkbox is not checked!"
                     $label1.ForeColor = 'Red'


Now run the form, in PowerShell studio press Ctrl + 5
You form look like below first.
Now just press on “Button” without ticking on the checkbox. And you will see that our label is changed to the “Checkbox is not checked”.

Now tick on the check and press the button again.
You can see that text of our label is changed to “Checkbox is checked”.

Video on using checkbox

That’s all of now.

See you in my next blog post.

Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021