SALES: 1-800-867-1380
2 out of 2 rated this helpful - Rate this topic

Manage Virtual Machines Using Windows Azure Cmdlets

Updated: October 29, 2012

"You can use the Windows Azure cmdlets to manage the virtual machines in your Windows Azure subscriptions. The following procedures will help you manage virtual machines:"

For more information about how to get started using Windows Azure cmdlets, see Use Windows Azure Cmdlets.

Add a data disk to a virtual machine

This section shows you how to add a data disk to a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

To add a data disk to an existing virtual machine, you must use the Get-AzureVM cmdlet to retrieve an object from Windows Azure that represents the virtual machine and then add the data disk to the object configuration. You add a new or existing data disk to the object by using the Add-AzureDataDisk cmdlet and the Update-AzureVM cmdlet.

Add a data disk

Follow these steps to add a data disk to a virtual machine.

To add a data disk to a virtual machine

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine that you want add a disk to.

  2. Specify the virtual machine you want to modify, specify the data disk that you want to add to the virtual machine, and then update the virtual machine. In this first example, you'll create a new data disk of 64GB.

    Add a new data disk

    PS C:\> Get-AzureVM -ServiceName "mysvc" -Name "myVM" | Add-AzureDataDisk -CreateNew -DiskSizeInGB 64 -LUN 1 -DiskLabel "Data" | Update-AzureVM
    

    Add an existing data disk from the disk library

    PS C:\> Get-AzureVM -ServiceName "mysvc" -Name "myVM" | Add-AzureDataDisk -Import -DiskName "myData" -LUN 2 | Update-AzureVM
    

    Add an existing data disk from your blob storage account

    PS C:\> Get-AzureVM -ServiceName "mysvc" -Name "myVM" | Add-AzureDataDisk -ImportFrom -MediaLocation "https://mystore01.blob.core.windows.net/mycontainer/mydata01.vhd" -disklabel "myData02" -LUN3
    

    Add a data disk to a new virtual machine

    PS C:\> New-AzureVMConfig -Name "MyLxVM2" -InstanceSize Small -ImageName (New-AzureVMImage)[8].ImageName | Add-AzureProvisioningConfig -Linux -Password $pwd -LinuxUser $lxusr | Add-AzureDataDisk -Create -DiskSizeInGB 64 -LUN 1 -DiskLabel "Data" | New-AzureVM -ServiceName "mysvc"
    

For more information about creating a custom virtual machine, see How to Create a Custom Virtual Machine

Interested in using the Windows Azure Management Portal to do this? See, How to Attach a Data Disk to a Virtual Machine.

Next Steps

Detach a data disk from a virtual machine

This section shows you how to detach a data disk from a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

To detach a data disk from a virtual machine, you must use the Get-AzureVM cmdlet to retrieve an object from Windows Azure that represents the virtual machine and then remove the data disk from the object configuration. You remove the data disk from the configuration by using the Remove-AzureDataDisk cmdlet and the Update-AzureVM cmdlet.

You can see a list of data disks that are attached to a virtual machine by using the Get-AzureDataDisk cmdlet. When you detach a data disk from a virtual machine, the data disk is maintained in storage and can be re-attached to the original virtual machine, or another virtual machine.

Detach a data disk

Follow these steps to detach a data disk from a virtual machine.

To detach a data disk

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine that you want to remove a disk from.

  2. Get a list of data disks attached to a specific virtual machine.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -name "myVM01" | Get-AzureDataDisk
    
  3. Remove the data disk at LUN 1 from the configuration, and update the virtual machine.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -name "myVM01" | Remove-AzureDataDisk -LUN 1 | Update-AzureVM
    

    When the operation is complete, the Update-AzureVM cmdlet returns an operation status, along with the operation ID. The Remove-AzureDataDisk cmdlet does not remove the disk from the disk repository, but only detaches the disk from the virtual machine.

Interested in using the Windows Azure Management Portal to do this? See, How to Detach a Data Disk from a Virtual Machine.

Next Steps

Log on to a virtual machine by using a Remote Desktop Connection

This section shows you how to log on to a virtual machine in Windows Azure by using the Get-AzureRemoteDesktopFile cmdlet to create and open a Remote Desktop session.

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

You can use Remote Desktop to log on to your Windows virtual machine. By doing this you can access the full suite of Windows Server management tools. The Get-AzureRemoteDesktopFile cmdlet downloads an RDP file to your local computer. You can use this RDP file to connect to the virtual machine. Or, you can directly start a Remote Desktop session by using the Get-AzureRemoteDesktopFile cmdlet with the -Launch parameter.

Log on to a Windows virtual machine

Follow these steps to log on to a Windows virtual machine.

To log on to a Windows virtual machine

  1. Download an RDP file to your local desktop that you can use later to log on to the machine.

    PS C:\> Get-AzureRemoteDesktopFile -ServiceName "mysvc01" -name "myVM01" -LocalPath "$ENV:userprofile\Desktop\myVM01.rdp"
    

    An RDP file named "myVM01.rdp" is saved on your desktop. The RDP file has the details to connect to the "myVM01" virtual machine hosted on the Windows Azure cloud service named "mysvc01".

    TipTip
    The $ENV:userprofile portion of the local path in this command resolves to the top of your profile path. You can see a list of all the available values on the ENV: drive by typing dir env: in a PowerShell command window.

  2. Double-click on the RDP file on your desktop to start a Remote Desktop session with the virtual machine.

    - Or -

    Directly launch a remote desktop session.

    PS C:\> Get-AzureRemoteDesktopFile -ServiceName "mysvc01" -name "myVM01" -Launch
    

Interested in using the Windows Azure Management Portal to do this? See, How to Log on to a Virtual Machine Running Windows Server 2008 R2.

Change disk properties

This section shows you how to change the properties of the disks that are attached to a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

You can control the host caching property of both the data and the operating system disks of virtual machines in Windows Azure. The available caching modes for data disks are None, ReadOnly and ReadWrite. For operating systems, the available caching modes are ReadOnly and ReadWrite.

Change the properties of a data disk

Follow these steps to change the properties of a data disk that is attached to a virtual machine.

To change the properties of a data disk

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Get a list of data disks attached to a specific virtual machine.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -name "myVM01" | Get-AzureDataDisk
    
  3. Change the caching mode of a data disk. In this example, the cache mode is being changed to None.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -Name "myVM01"  | Set-AzureDataDisk "None" -LUN 0 | Update-Azure
    

    The caching mode to is set to None for the data disk attached at LUN 0.

Change the properties of an operating system disk

Follow these steps to change the properties of an operating system disk that is attached to a virtual machine.

To change the properties of an operating system disk

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Change the caching mode of an operating system disk for a specified virtual machine. In this example, the cache mode is being changed to ReadOnly.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -Name "myVM01" | Set-AzureOSDisk "ReadOnly" | Update-Azure
    
    WarningWarning
    When you update the caching mode of an operating system disk for a running virtual machine, the machine is restarted.

Next Steps

Change the configuration of a virtual machine

This section shows you how to change the configuration of a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

You can change the size of a virtual machine to enable more (or less) computing resources, or allow for additional disks. However, before you can reduce the size of a virtual machine, you must detach any data disks that are not supported by the smaller size. For more information about detaching a data disk, see Detach a data disk from a virtual machine.

ImportantImportant
When you change the size of a virtual machine, it is reprovisioned and the IP address of the virtual machine might change.

Change the configuration of a virtual machine

Follow these steps to change the configuration of a virtual machine.

To change the configuration of a virtual machine

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Specify the virtual machine that you want to change the size of.

    PS C:\> $myVM = Get-AzureVM -ServiceName "mysvc01" -Name "myVM01"
    
  3. Set the size of the specified virtual machine.

    PS C:\> Set-AzureVMSize -VM $myVM1 -InstanceSize "ExtraSmall" | Update-AzureVM
    

Next Steps

Import or Export the state of a virtual machine

This section shows you how to import or export the state of a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

You can save the state of a virtual machine and recreate it in Windows Azure. The state of the virtual machine is saved to an XML file by using the Export-AzureVM cmdlet. If you then use the Remove-AzureVM cmdlet to delete the original virtual machine, and Import-AzureVM and New-AzureVM, you recreate the virtual machine. However, this can cause the IP address of the virtual machine to change.

Export the state of a virtual machine

Follow these steps to export the state of a virtual machine.

To export the state of a virtual machine

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Export the state of a single virtual machine in a cloud service.

    PS C:\> Export-AzureVM -ServiceName "mysvc01" -name "myVM01" -path "C:\temp\save_myVM01.xml"
    

    - Or -

    Export the state of all the virtual machines in a cloud service.

    PS C:\> Export-AzureVM -ServiceName "mysvc01" -path "C:\temp\save_myVMs.xml"
    

Create a virtual machine from a saved state

Follow these steps to create a virtual machine from a saved state.

To create a virtual machine from a saved state

  1. If you have not already done so, delete the virtual machines from which the state was exported.

    Remove-AzureVM -ServiceName "mysvc01" -name "myVM01"
    
  2. Create the virtual machine from the saved state.

    PSH Import-AzureVM -path "C:\temp\save_myVM01.xml" | New-AzureVM -servicename "mysvc01"
    

    The virtual machine will have the same disks attached as the original virtual machine, but because it is a new deployment, it might have a different IP address.

Start or Stop a virtual machine

This section shows you how to start or stop a virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets, you need to:

  • Create a Windows Azure subscription

  • Create a Windows Azure Storage account for your subscription

  • Download and install the Windows Azure PowerShell module

  • Configure a management certificate for the subscription

  • Configure connectivity to your subscription

For more information about completing these tasks, see Get Started with Windows Azure Cmdlets.

Concepts

You can start or stop a virtual machine at any time in Windows Azure. Unlike most Windows Azure cmdlets, you can do this either by specifying the Windows Azure service name and virtual machine name as strings, or by using the Get-AzureVM cmdlet.

Start a virtual machine

Follow these steps to start a virtual machine.

To start a virtual machine

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Start a virtual machine by using the cloud service name and the virtual machine name.

    PS C:\> Start-AzureVM -ServiceName "mysvc01" -name "myVM01"
    

    - Or -

    Start a virtual machine by using an object.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -name "myVM01" | Start-AzureVM
    

Stop a virtual machine

Follow these steps to stop a virtual machine.

To stop a virtual machine

  1. Get a list of virtual machines in the current Windows Azure subscription.

    PS C:\> Get-AzureVM
    

    The Get-AzureVM cmdlet returns a list of all the virtual machines running in all the cloud services associated with the current Windows Azure subscription. You can use this to see the exact name of the cloud service and of the virtual machine.

  2. Stop a virtual machine by using the cloud service name and the virtual machine name.

    PS C:\> Stop-AzureVM -ServiceName "mysvc01" -name "myVM01"
    

    - Or -

    Stop a virtual machine by using an object.

    PS C:\> Get-AzureVM -ServiceName "mysvc01" -name "myVM01" | Stop-AzureVM
    

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.