Beginning with Windows Azure Using PowerShell

I recently created an account to use Windows Azure to create some virtual machines that I can then use to work with more systems than I can usually do given my current hardware. This also presents a great opportunity for me to try out the Windows Azure PowerShell module and see what it can do. So that means you can join me for this little ride into the world of Azure and PowerShell and see what we can find!

Download The Module

First thing to do is download the Azure module from the following link: http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409

This will open up an installer which will allow you to install the SDK as well as the PowerShell module. Once completed you can then access the PowerShell Azure module to make the initial connection to your subscription.

From a PowerShell prompt, run the following command:

Get-AzurePublishSettingsFile

This will open up a webpage that will automatically download a subscription file that you will then use in the next command. This file contains the necessary information that will allow you to connect to your managed Azure subscription.

image

Now we can import these settings to use in the connection.

Import-AzurePublishSettingsFile -PublishSettingsFile `
"C:\Users\Administrator\Downloads\AzureSubscription.publishsettings"

image

Now we can take a look at the Azure subscription using Get-AzureSubscription. Also be sure to delete the publishsettings file as there is credential information that you really do not need readily available for someone to possible steal.

Get-AzureSubscription

image

I can view my current virtual machines using Get-AzureVM

Get-AzureVM

image

I’ve only got a couple of virtual machines so far and they are currently powered off.

A nice thing that I like is that there are already images available to use when creating a virtual machine. Others may need something more granular to configure, but for me, I just want a VM spun up with Windows 2012 so I can jump in and try some things out. But before I can do that, I need to figure out what images are available for Windows 2012.

image

Whoops! I guess that wildcards are not welcome here. Also note that we are sending traffic to a web service that then responds back with our information. Lets do some filtering with Where-Object instead.

Get-AzureVMImage | Where {
    $_.label -match "windows 2012"
} | Format-Table imagename,description

image

The imagename is a little crazy, but we can see what images are already available to use as far as Windows 2012 goes.

Before I can create the VM, I need to specify my storage account in my subscription.

Get-AzureSubscription | 
Set-AzureSubscription -CurrentStorageAccount 'portalvhdsbckxgx4d7p6dq' -Verbose

image

You will notice that it only hit one of my 3 subscriptions. This is because it only updates the subscription that is default. In this case it is my Visual Studio Subscription.

Get-AzureSubscription | Select SubscriptionName,IsDefault,CurrentStorageAccount

image

So with that, lets spin up a new VM using one of these images.

$password = ************
$VMImage = (Get-AzureVMImage | Out-GridView -PassThru)
$vm = New-AzureVMConfig -Name MS02 -InstanceSize ExtraSmall -ImageName $VMImage.ImageName -Verbose | 
Add-AzureProvisioningConfig -Windows -AdminUsername proxb -Password $password -Verbose
New-AzureVM -ServiceName DC1-PROX -VMs $vm -Verbose

I am making it a little easier on myself to pick out an image by piping the output of Get-AzureVMImage to Out-Gridview and specifying the –Passthru parameter which will take that selection and output the object into the next cmdlet in the pipeline.

image

The command will move on to take that image and make some additional configurations and then work to provision the virtual machine.

image

It’s not quite finished yet…

image

And after a couple of minutes, MS02 is now ready for primetime!

image

For some weird reason, the Get-AzureVM cmdlet doesn’t appear to be respecting the –Name parameter and only giving me the VM that I want. Could be a bug or it could be something else…

image

I really do not need this running right now, so I will go ahead and shut it down.

Stop-AzureVM -Name MS02 -Verbose

Because this is the last VM in my environment, I get a confirmation on whether to continue with this action. I could specify the –Force parameter to allow this to continue without a confirmation prompt.

image

That is all so far with my work on provisioning a virtual machine in my Azure environment with PowerShell. I am unsure as to just how much I will be using Azure for other than simple virtual machines to test various script, but if I do something new or different than what has been shown here, I will be sure to blog it!

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s