📜 ⬆️ ⬇️

Save resources when using virtual machines in Windows Azure

image
Consider two scenarios of working with virtual machines in Windows Azure, which will help save money and time:


To solve these problems, we will use PowerShell cmdlets for Windows Azure.

Preliminary actions


We imply that you already have an account in Windows Azure.
Download and install PowerShell cmdlets for Windows on the official site .
Now you need to get a file with settings for publishing and subscription information. To do this, start Windows Azure PowerShell and execute:
Get-AzurePublishSettingsFile 

As a result, the page https://windows.azure.com/download/publishprofile.aspx opens and save the file.
Next, do:
 Import-AzurePublishSettingsFile <mysettings>. publishsettings 

Then the file with the subscription data can be deleted.

We export and delete the virtual machine.


To export the virtual machine settings to an XML file, use the Export-AzureVM cmdlet :
 Export-AzureVM -ServiceName '<CloudService>' -Name '<VmName>' -Path 'c:\VMs\VMstate.xml' 

And to remove Remove-AzureVM :
 Remove-AzureVM -ServiceName '<CloudService>' -Name '<VmName>' 

However, Remove-AzureVM does not delete the VHD, and all your data is not lost.
When you need to start using a virtual machine, use the previously exported file and Import-AzureVM cmdlet :
 Import-AzureVM -Path 'c:\VMs\VMstate.xml' | New-AzureVM -ServiceName '<CloudService>' -Location '<Location>' 

The disadvantage of the above steps is that if you need to export and delete several machines, it will be inconvenient.

Export and delete all virtual machines in the Cloud Service


 Get-AzureVM -ServiceName '<CloudService>' | foreach { $path = 'c:\VMs\' + $_.Name + '.xml' Export-AzureVM -ServiceName '<CloudService>' -Name $_.Name -Path $path } Remove-AzureDeployment -ServiceName '<CloudService>' -Slot Production –Force 

Importing virtual machines into the existing Cloud Service


 $vms = @() Get-ChildItem 'c:\VMs\' | foreach { $path = 'c:\VMs\' + $_ $vms += Import-AzureVM -Path $path } New-AzureVM -ServiceName '<CloudService>' -VMs $vms 

')

Source: https://habr.com/ru/post/147372/


All Articles