So I wrote some PowerShell functions to help me out. The most challenging part was the lack of working procedures and the constant flux of the Azure SDK, which presented itself in changed properties, differing methods and unexpected behaviour...
The management portal is significantly more stable now.
The script has a IaaS focus and consequently will only be of help in managing Virtual Machines and their Storage, but with a little more work can be extended to .
This script is on GitHub (Manage-Azure) and I encourage any with an interest to contribute to it's further development.
Anyway as of October 2013 the script works, so lets go in to their setup and use case.
- Ensure you have a Microsoft Azure account.
- Download the scripts from: Manage-Azure
- Extract them to a path on your local machine.
- Open a PowerShell window > import the script ". C:\Your-Location\Manage-Azure.ps1":
Here you can see my PS execution policy doesn't allow me to run the script, and after I chnage the policy the script tells me I need to download the Azure Cmd line tools (bcos I'm testing on a completely vanilla Win7 VM).
- Unfortunately there's no way around downloading the SDK/Cmd line tools dependencies :(.
- Once the script is imported you have 2 functions available to you:
- Type in the function and a list of operations will popup.
- If a "publishsettings" file isn't in the script location, it will ask you to choose the directory where it's located... download yours if you haven't already.
- Choose your subscription if you have more than 1.
This function provides Storage operations.
- Copy Blob.
This operation enables copying blobs from container to container, and from storage account to storage account. If the storage accounts are in different data centers the copy operation can take a significant amount of time... eg: 127GB from Ireland to Hong Kong ~ 35minutes.
- Delete Blob.
Delete 1 or more blobs.
- Add Disk
Just like the Windows Azure Management Portal, it creates a disk from a blog reference.
- Remove Disk
Just like the Windows Azure Management Portal
- Break Lease
Sometimes a blob will have a lease by an object that doesn't exist, this used to be a big problem before October 2013 when VM's would frequently get stuck on starting, now not so much.
- New Snapshot
Takes a blob snapshot.
- Restore Snapshot
Restores a blob snapshot.
This function provides VM operations.
Starts 1 or more VM's; this operation does one at a time and waits for them to start.
Note: They don't always start at the same speed.
Stops 1 or more VM's; this operation does one at a time and waits for them to stop.
This operation will stop a VM if started, copy the disk blobs attached to the VM to the backup container specified in the PS script ($BackupPath) and Start the VM if it was originally started.
Note: In this screenshot you can observe iios-1 was "stopped" while iios-2 was "started" and " vhd-backups" didn't exist, so was created.
Note: Here iios-2 has 2 attached disks.
This operation will stop a VM if started, Export the VM config, detach all disks, delete the disk blobs, remove the VM, let you select a blob to restore from the backup container, copy it to the vhds container, create disks for the blobs, recreate the VM from the config file and Start the VM if it was originally started.
- Export VM XML
This just saves the VM configuration to an XML file.
- New VM XML
This creates a VM from an XML configuration file. This comes in handy if a Restore operation fails for some reason, or you Delete the VM while keeping the attached disks.
Known Issues - Improvements
- Operation behaviour is inconsistent; you can perform a restore and it will fail at some point, one time and then do exactly the same operation and it works the next. The seeming randomness of it also makes it challenging to resolve.
Note: Here you can see while trying to perform a Restore the script fails when recreating the VM from the config file. It's easy to recover from this point by just calling the "New VM XML" operation, but then this also fails when starting the VM even though the VM starts successfully... pretty annoying.
- Reuse of functions; I've been a little lax in reusing functions like copy/delete blob are used by multiple operations in Manage-AVM, but I don't use the Manage-AStorage functions.
- Better error handling; most Azure operations have an Id with returned properties indicating success/failure in most cases I don't use these.
- Logging needs improving, I capture Start and Stop VM logs but that's about it.