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.
Run the following commands:
# Set the Windows PowerShell Execution Policy
Set-ExecutionPolicy RemoteSigned
# 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:
Save it in your local machine.
Import-AzurePublishSettingsFile “<complete path and filename of saved file>”
#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.
Ensure that all export files have been created correctly:
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
}
Before
After
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.
Before
After
No hay comentarios:
Publicar un comentario