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.
Now we can import these settings to use in the connection.
Import-AzurePublishSettingsFile -PublishSettingsFile ` "C:\Users\Administrator\Downloads\AzureSubscription.publishsettings"
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
I can view my current virtual machines using Get-AzureVM
Get-AzureVM
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.
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
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
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
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.
The command will move on to take that image and make some additional configurations and then work to provision the virtual machine.
It’s not quite finished yet…
And after a couple of minutes, MS02 is now ready for primetime!
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…
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.
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!