...building hybrid clouds that can support any device from anywhere
Hello once again!
Here we are at the end of this blog series: Part 4 of the Automating Hybrid Clouds with Windows Azure and PowerShell blog series - Public Cloud Environment Deprovisioning PowerShell Examples. I do think you will be surprised to see how easy it is to remove everything you added.
Before we move on to this content, here are the requisite references to the previous three parts of this blog series:
Okay, now for the good part, let’s see what it takes to remove everything you worked so hard to put up there in the first place.
The following is a list of the high level concept commands that will be covered in this post:
We obviously need a few things before we get started:
Once again, we have to ensure a connection to the Windows Azure Subscription has been established before we proceed.
It is entirely possible this is already Selected/Set on the system where have been executing the Windows Azure PowerShell commands.
If this is the case, simply execute the following command:
If the Get-AzureSubscription command results in something like this, you are good to go:
Note The CurrentStorageAccountName field is important for these examples. If this is blank, you will have to complete more steps before proceeding (see below).
If the Get-AzureSubscription command results in a NULL value, you will have to complete the necessary steps for an Established Windows Azure Subscription Connection.
This region is covered 100% in Part 2 of this blog series.
For reference, here is the link: Automating Hybrid Clouds with Windows Azure and PowerShell (Part 2): Public Cloud Environment Provisioning PowerShell Examples
If the Get-AzureSubscription command results in NULL CurrentStorageAccountName field data, execute the following commands:
Note The variables on lines 001 and 002 should be changed to fit your environment/deployment.
With the Connection to a Windows Azure Subscription Established, Deprovisioning of Windows Azure resources associated with that Subscription and Storage Account can be completed.
Because many of the commands in the Deprovision process are very simple, I have grouped them into sections that can easily be executed together. They can be executed individually if you like, this is just for the example.
Note Within the examples, I have repeated the required variable declarations to successfully execute each of the commands (per section).
Final thing before we get to the commands - here is a screenshot of my…
Note I will also show individual breakdown screenshots for each of the Deprovision sections below.
Oh, and because many of the resources have dependencies, be sure to execute them in the recommended order here.
Note As can be seen, all other variables are derived from the $ProjectName variable. This is consistent with the example Provisioning PowerShell (and Workflow) Examples. Feel free to leverage/update the variables as desired to fit your environment/deployment.
Note The image above does not show that the “BCBWFDemo…” Disk is attached to a Virtual Machine. This is usually not the case directly after a Virtual Machine is removed. I just happened wait long enough before taking the screenshot and executing the next command. The following commands do take this “wait time” into account with a simple example of a “check for status” loop based on Disk Data.
Note Obviously this is a simple example of what you can do to remove the associated Windows Azure VM Disk for the Project VM. There are many ways to program the wait time. This is one of them. You may also just want to wait until the disk is fully detached from other resources by watching it in the portal).
Note Removal of the Windows Azure Storage Account will perform a cascading removal of the Windows Azure Storage Containers and Windows Azure Storage Blob(s). I will break those examples out separately, but if you want to remove everything all at once, simply leverage the following command.
Note Depending on your starting point for this example, you may already have defined the $AzureStorageAccountName variable.
Note With the removal of the Windows Azure Storage Account went the associated Windows Azure Storage Containers and Windows Azure Storage Blobs. The following are the individual example commands for each of those if specified removal is desired.
And just like that, all the project specific Windows Azure Environment resources have been removed.
Okay, once again, here is the portion of the blog post where I put all the above examples together in one copy/paste-able script. You will see, for the sake of simplicity (and line count), I did not add “If Checking” into these examples – feel free to add whatever wrapper logic you want, as desired. Okay, here it is (a destructive 92 lines of PowerShell):
Note Since it worked out so nicely last time, I broke the “all together” script into collapsible regions.
Important “Automation” of these Deprovision tasks is very destructive and should be done with care. In fact, I would recommend only executing these script examples one region at at time (if not more granular) to ensure no accidental removal of resources occurs.
In the spirit of “Removal”, here is a little script I use when I want to clear out the Selected/Set Windows Azure Subscription from the machine performing all the Windows Azure PowerShell commands:
Note I intentionally did not included this example script in the above “all together” section. I am not actually sure how often it will be used, but I wanted to provide it just in case.
Well, that is it for this Blog Series on Hybrid Cloud Automation with Windows Azure and PowerShell.
All that is left to do, is start exploring and developing use cases to leverage the example scripts within Parts 2, 3 and 4!
I broke this “Automating Windows Azure” topic up into four posts – primarily to make it easier to reference externally (based on varied interest levels).
As promised, the following is the link to the TechNet Contribution and Download for the examples (from all parts of the blog series).
The download (Hybrid Cloud Automation Toolkit - Windows Azure and PowerShell.zip) includes the following (4) files:
Download the Hybrid Cloud Automation Toolkit - Windows Azure and PowerShell from TechNet Gallery here:
Thanks for checking out this blog series! For more information, tips/tricks, and example solutions for Automation within System Center, Windows Azure Pack, Windows Azure, etc., be sure to check out the other blog posts from Building Clouds in the Automation Track!