Windows Azure – Manage your VM

Once all our stuff is prepared thanks to previous posts:

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


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
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


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 -ServiceName pwrshellxlab -Name pwrshell-ok
OperationDescription                    OperationId                             OperationStatus
--------------------                    -----------                             ---------------
Restart-AzureVM                         e92d560b-957d-8fbf-bbf3-029f543d3bcb    Succeeded


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="" xmlns:xsi="">
    <ConfigurationSet xsi:type="NetworkConfigurationSet">
  <DataVirtualHardDisks />

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 !