Windows Azure – Manage your VM
Once all our stuff is prepared thanks to previous posts:
- Account configured
- The storage is created
- The network works
- VM(s) are running
- And Endpoints are listening
You way have to take actions on your VM. Windows Azure prodives a set of cmdlets to do this. We already used Update-AzureVM and New-AzureVM, to change configuration and create one, but obvisouly, you can do more !
Get-Command -Module Azure | ? Name -like "*AzureVM"
CommandType Name ModuleName ----------- ---- ---------- Cmdlet Export-AzureVM Azure Cmdlet Get-AzureVM Azure Cmdlet Import-AzureVM Azure Cmdlet New-AzureVM Azure Cmdlet Remove-AzureVM Azure Cmdlet Restart-AzureVM Azure Cmdlet Start-AzureVM Azure Cmdlet Stop-AzureVM Azure Cmdlet Update-AzureVM Azure
As you see, many actions are possible. Let’s start by the common ones… i won’t explain what the cmdlets’ll do, i think it’s clearly 🙂
- Start-AzureVM
- Stop-AzureVM
- Restart-AzureVM
- Remove-AzureVM
Stop-AzureVM
If you have only one VM remaining in your subscription, and want to delete a VM you can encounter this
Stop-AzureVM -ServiceName pwrshellxlab -Name pwrshell-ok
Confirmer The specified virtual machine is the last virtual machine in this deployment. Continuing will result in a new IP address for your deployment. To shut down without losing the deployment IP use -StayProvisioned. [O] Oui [N] Non [S] Suspendre [?] Aide (la valeur par défaut est « O ») :
As it’s said, the solution is to use the -StayProvisionned switch, if you wan’t to stop completly the VM and can loose your IP configuration, it’s possible by using the -Force switch.
Stop-AzureVM -ServiceName pwrshellxlab -Name pwrshell-ok -StayProvisioned
OperationDescription OperationId OperationStatus -------------------- ----------- --------------- Stop-AzureVM cf05c498-3d07-8def-a219-b8545e723de7 Succeeded
 Start-AzureVM
Ok, now our VM is stopped, let’s start it !
Start-AzureVM -ServiceName pwrshellxlab -Name pwrshell-ok
OperationDescription OperationId OperationStatus -------------------- ----------- --------------- Start-AzureVM 6a18ac85-bc85-8e13-b15d-1908c3ceab68 Succeeded
Nothing more simple… it’s the same for a restart.
Restart-AzureVM
Restart-AzureVM -ServiceName pwrshellxlab -Name pwrshell-ok
OperationDescription OperationId OperationStatus -------------------- ----------- --------------- Restart-AzureVM e92d560b-957d-8fbf-bbf3-029f543d3bcb Succeeded
 Remove-AzureVM
Remove-AzureVM -ServiceName pwrshellxlab -Name pwrshell-ok
OperationDescription OperationId OperationStatus -------------------- ----------- --------------- Remove-AzureVM 7adf793c-1e54-83d4-ba0b-425bcf3d438b Succeeded
Import or Export a Virtual Machine
If you want to save a virtual machine and recreate it from scratch with a blank data, it’s possible. First of all, you must have export it to a XML file.
Export-AzureVM -ServiceName pwrshellxlab -Name pwrshell-2 -Path F:\Test.xml
You have now a beautiful XML file locate in the path designed in the command, it should be something like this…
<?xml version="1.0" encoding="utf-8"?> <PersistentVM xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ConfigurationSets> <ConfigurationSet xsi:type="NetworkConfigurationSet"> <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType> <InputEndpoints> <InputEndpoint> <LocalPort>3389</LocalPort> <Name>RDP</Name> <Port>59595</Port> <Protocol>tcp</Protocol> <Vip>137.117.209.155</Vip> <EnableDirectServerReturn>false</EnableDirectServerReturn> </InputEndpoint> <InputEndpoint> <LocalPort>5986</LocalPort> <Name>WinRmHTTPs</Name> <Port>59372</Port> <Protocol>tcp</Protocol> <Vip>137.117.209.155</Vip> <EnableDirectServerReturn>false</EnableDirectServerReturn> </InputEndpoint> </InputEndpoints> <SubnetNames> <string>France</string> </SubnetNames> </ConfigurationSet> </ConfigurationSets> <DataVirtualHardDisks /> <OSVirtualHardDisk> <HostCaching>ReadWrite</HostCaching> <DiskName>pwrshellxlab-pwrshell-2-0-201403212036350129</DiskName> <SourceImageName>a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201401.01-en.us-127GB.vhd</SourceImageName> <OS>Windows</OS> </OSVirtualHardDisk> <RoleName>pwrshell-2</RoleName> <RoleSize>Small</RoleSize> <RoleType>PersistentVMRole</RoleType> <NoExportPrivateKey>false</NoExportPrivateKey> <NoRDPEndpoint>false</NoRDPEndpoint> <NoSSHEndpoint>false</NoSSHEndpoint> <DefaultWinRmCertificateThumbprint>906A36B18F354180F0580E08FD739AA41A843C2A</DefaultWinRmCertificateThumbprint> </PersistentVM>
Note: Using Export-AzureVM, followed by Remove-AzureVM and then Import-AzureVM to recreate a virtual machine can
cause the resultant virtual machine to have a different IP address than the original.
And now, we just have to import it and create a new from it !
Import-AzureVM -Path F:\Test.xml | New-AzureVM -ServiceLabel "pwrshellnewsvc"
But this is not working…
So i’ve done a Get-Help Import-AzureVM -examples and see nothing more. Let’s add an AffinityGroup to the New-AzureVM cmdlet.
Import-AzureVM -Path F:\Test.xml | New-AzureVM -ServiceLabel "pwrshellnewsvc" -AffinityGroup PWRSLL
Not working too…
Soo… let’s try with an existing service label
Import-AzureVM -Path F:\Test.xml | New-AzureVM -ServiceLabel "pwrshellxtst" -AffinityGroup PWRSHELL
And guess what ? It’s not working too 🙂 I got the same error as bellow.. So if someone from Microsoft read this post and he/she have a solution, feel free to give me a hint at least or the solution.
Ok, that’s all for today.
In the next post, we’ll talk about backup your VM stuff !
Regards.