jueves, 18 de julio de 2013

De-provision / Re-provision your Azure Lab Environment via PowerShell

Share it Please

Your functional SharePoint lab environment is now complete, but if you’re like me, you won’t be using this lab environment 24x7 around-the-clock. As long as the virtual machines are provisioned, they will continue to accumulate compute hours against your Windows Azure account regardless of virtual machine state – even in a shutdown state!

We can leverage the Windows Azure PowerShell module to de-provision our lab virtual machines when not in use and re-provision our lab virtual machines when we need them again in just 5-10 minutes.

Launch PowerShell for Windows Azure. Right-click on the Windows PowerShell shortcut on the desktop and select Run as Administrator to launch Windows PowerShell with Administrative Rights.

clip_image002

Run the following commands:

# Set the Windows PowerShell Execution Policy

Set-ExecutionPolicy RemoteSigned

clip_image004

# Import the Windows Azure PowerShell Module

Import-Module Azure

# Download and Import a Windows Azure publish settings file

Get-AzurePublishSettingsFile

Internet Explorer will be opened automatically and settings file will be downloaded:

clip_image006

Save it in your local machine.

Import-AzurePublishSettingsFile “<complete path and filename of saved file>”

clip_image008

#type the name of your VMs

$myVMs = @("angellab001","angellabAD01")

Foreach ($myVM in $myVMs) {

           Stop-AzureVM -ServiceName $myVM -Name $myVM

          $ExportPath = "C:\AzureStuff\ExportAzureVM-$myVM.xml"

          Export-AzureVM -ServiceName $myVM -name $myVM -Path $ExportPath

}

You can create a PowerShell script with these commands and run it from the console.

clip_image010

Ensure that all export files have been created correctly:

clip_image012

Now you can proceed to de-provisioning your lab environment. You need to run the following command (you can create a script and run it from console too):

# De-provisioning your lab

$myVMs = @("angellab001","angellabAD01")

Foreach ( $myVM in $myVMs ) {

              Remove-AzureVM -ServiceName $myVM -name $myVM

}

clip_image014

Before

clip_image016

After

clip_image018

Just the cloud services (Affinity Group, Virtual Network, Storage Account) exist, VMs have been removed.

To re-provisioning your lab environment you have to run the following commands or create a script:

#type your virtual network name

$myVNet = "angellabnet01"

#type your VMs name

$myVMs = @("angellab001","angellabAD01")

#type your storage account

$myStorageAccount = "angellabstore01"

Get-AzureSubscription |

       Set-AzureSubscription -CurrentStorageAccount $myStorageAccount

Foreach ($myVM in $myVMs ) {

           $ExportPath = "C:\AzureStuff\ExportAzureVM-$myVM.xml"

          Import-AzureVM -Path $ExportPath | New-AzureVM -ServiceName $myVM -VNetName $myVNet

           Start-AzureVM -ServiceName $myVM -name $myVM

}

Take into account the order of the VMs in $myVMs vector. If you have an Active Directory server, it should be the first one to re-provision before of the rest of servers that are joined to the domain. Or if you have a SharePoint server + a SQL server, SQL server should be re-provisioned before the SharePoint one because this contains the SharePoint configuration databases needed to get SharePoint server running.

clip_image020

Before

clip_image021

After

clip_image023

No hay comentarios:

Publicar un comentario

Project Mgmt. Professional

Project Mgmt. Professional

AWS Architect

AWS Architect

ITIL Fundamentals

ITIL Fundamentals