Export (0) Print
Expand All
3 out of 5 rated this helpful - Rate this topic

Create or Delete Virtual Machines Using Windows Azure Cmdlets

Updated: June 11, 2013

You can use the Windows Azure cmdlets to create virtual machines in the configuration that you need for your solution. The following procedures will help you create virtual machines:

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

Quickly create a virtual machine

This section shows you how to quickly create a virtual machine in Windows Azure by using the Windows Azure New-AzureQuickVM cmdlet.

Prerequisites

Before you can use Windows Azure cmdlets to create virtual machines in Windows Azure, 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 the New-AzureQuickVM cmdlet to create a Windows Azure Virtual Machine in a single command. The cmdlet enables you to create a Windows virtual machine or to create a Linux virtual machine. You can create a new virtual machine in an existing Windows Azure cloud service, or you can create a new cloud service by using the Location parameter.

The following parameters are required for the New-AzureQuickVM cmdlet:

  • Linux or –Windows - The type of virtual machine to create

  • AdminUsername – The name of the administrative account you want to use manage the operating system run by the virtual machine

  • ImageName - The name of the image to use to create the virtual machine

  • Password - The password for the administrative account

  • ServiceName - The name of the Windows Azure cloud service

  • Location - Only required if you are creating a new cloud service

  • LinuxUser - Only required for Linux virtual machines, this is the name of the Linux administrator account to create

Create the Windows virtual machine

Follow these steps to quickly create a Windows virtual machine in a new cloud service.

To create the Windows virtual machine

  1. Get a list of images that you can use to create the virtual machine.

    PS C:\> $images = Get-AzureVMImage
    

    $images represents a Windows PowerShell list object. You can see the contents of the list by typing $images at the Windows PowerShell command line. Pick a Windows Server image from the list.

  2. Get a list of Windows Azure locations to host the virtual machine.

    PS C:\> $locations = Get-AzureLocation
    

    The $locations variable represents a list of Windows Azure datacenter locations. You can see a list of these locations by typing $locations at the Windows PowerShell command line. The first location in the list is $locations[0] and the name of that location is $locations[0].name.

  3. Define the name of the cloud service and the password of the administrative account you will use for the virtual machine. The cloud service name must be unique.

    PS C:\> $mySvc = "myuniqueservicename01"
    
    PS C:\> $myPwd = "P@ssw0rd"
    
    TipTip
    You can test a cloud service name with the Test-AzureName cmdlet. If it returns $False, the name hasn't been used.

  4. Create the Windows virtual machine.

    PS C:\> New-AzureQuickVM -Windows -name "MyWinVM" -ImageName $images[4].imagename -ServiceName $mySvc -Location $locations[0].name -Password $myPwd
    

Interested in using the Windows Azure Management Portal to do this? See, How to Quickly Create a Virtual Machine.

Create the Linux virtual machine

Follow these steps to quickly create a Linux virtual machine in a new cloud service.

To create the Linux virtual machine

  1. Get a list of images that you can use to create the virtual machine.

    PS C:\> $images = Get-AzureVMImage
    

    The $images variable represents a Windows PowerShell list object. You can see the contents of the list by typing $images at the Windows PowerShell command line. Pick a Linux image from the list.

  2. Get a list of Windows Azure locations to host the virtual machine.

    PS C:\> $locations = Get-AzureLocation
    

    The $locations variable represents a list of Windows Azure datacenter locations. You can see a list of these locations by typing $locations at the Windows PowerShell command line. The first location in the list is $locations[0] and the name of that location is $locations[0].name.

  3. Define the name of the cloud service and the name and password of the administrative account for the virtual machine. The cloud service name must be unique.

    PS C:\> $mySvc = "myuniqueservicename01"
    
    PS C:\> $myPwd = "P@ssw0rd"
    
    PS C:\> $LxUsr = "linuxadmin"
    
    TipTip
    You can test a cloud service name with the Test-AzureName cmdlet. If it returns $False, the name hasn't been used.

  4. Create the Linux virtual machine in the existing service.

    PS C:\> New-AzureQuickVM -Linux -name "MyLxVM" -ImageName $images[8].imagename -ServiceName $mySvc -LinuxUser $LxUsr -Password $myPwd
    

Interested in using the Windows Azure Management Portal to do this? See, How to Quickly Create a Virtual Machine.

Next Steps

Create a custom virtual machine

This section shows you how to create a custom virtual machine in Windows Azure by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets to create virtual machines in Windows Azure, 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 create a custom Windows Azure Virtual Machine, you use the Windows Azure cmdlets to define the virtual machine configuration object, and then use the object to create the virtual machine.

The initial virtual machine object is created with the New-AzureVMConfig cmdlet, and the virtual machine is created with the New-AzureVM cmdlet. Additional provisioning configuration information is added to the object with the Add-AzureProvisioningConfig cmdlet.

You can create a custom virtual machine in a single command line by piping the output of each cmdlet to the next cmdlet in the process, but in this procedure, you'll use a Windows PowerShell variable, $VM1, to store the object at each stage of the process.

TipTip
The New-AzureVM cmdlet accepts a list of configuration objects, which enables you to easily create multiple virtual machines with one command. For more information, see Create multiple virtual machines.

Create a custom virtual machine

Follow these steps to create a custom Windows virtual machine in a new cloud service.

To create a custom virtual machine

  1. Get a list of images that you can use to create the virtual machine.

    PS C:\> $images = Get-AzureVMImage
    

    The $images variable represents a Windows PowerShell list object. You can see the contents of the list by typing $images at the Windows PowerShell command line.

  2. Get the name of the image that you want to use. The image name is a property of the image object in the list of images.

    PS C:\> $myOSImg = $images[3].ImageName
    

    $myOSImg represents the value of the ImageName property from the image that you chose.

    TipTip
    Windows PowerShell starts counting at zero.

  3. Get a list of available datacenter locations and get a datacenter location from the list.

    PS C:\> $locations = Get-AzureLocation
    
    PS C:\> $myLoc = $locations[0].name
    

    $locations represents a Windows PowerShell list object that contains all of the available datacenters for Windows Azure.

  4. Define the name of the cloud service and the password of the administrative account for the virtual machine. The cloud service name must be unique.

    PS C:\> $mySvc = "myuniqueservicename01"
    
    PS C:\> $myPwd = "P@ssw0rd"
    
    TipTip
    You can test a cloud service name with the Test-AzureName cmdlet. If it returns $False, the name hasn't been used.

  5. Create the virtual machine configuration object and assign it to the variable $VM1.

    PS C:\> $VM1 = New-AzureVMConfig –ImageName $myOSImg –Name "MyUniqueVMName" –InstanceSize "Small" –HostCaching "ReadWrite" –DiskLabel "System"
    
  6. Modify the virtual machine object to specify the Windows Server operating system and to set the password for the administrative account.

    PS C:\> $VM1 = Add-AzureProvisioningConfig –Windows –VM $VM1 –Password $myPwd
    
  7. Create the virtual machine, and create a new Windows Azure cloud service for it.

    PS C:\> New-AzureVM –VM $VM1 –ServiceName $mySvc –Location $myLoc
    

You can use the New-AzureVM cmdlet to create virtual machines with additional configuration options beyond those covered in this section, including additional storage, networking, authentication and availability options.

Interested in using the Windows Azure Management Portal to do this? See, How to Create a Custom Virtual Machine.

Next Steps

Add a new virtual machine to an existing service

This section shows you how to create a new Windows Azure Virtual Machine in an existing Windows Azure cloud service by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets to create virtual machines in Windows Azure, 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 create a Windows Azure Virtual Machine, you use the Windows Azure cmdlets to define the virtual machine configuration object, and then use the object to create the virtual machine. When you create a virtual machine, you can choose to create a new cloud service for the virtual machine, or to add the virtual machine to an existing cloud service. By adding the virtual machine to an existing cloud service, you enable interconnectivity between the new virtual machine, and existing virtual machines in that cloud service without having to do additional network configuration.

For more information about the concepts used by the Windows Azure cmdlets to create a virtual machine, see Concepts in Create a custom virtual machine.

Add a virtual machine to a cloud service

Follow these steps to add a new virtual machine to an existing cloud service.

To add a virtual machine to an existing cloud service

  1. Get a list of the names of Windows Azure cloud services you can add a virtual machine to.

    PS C:\> $mySvcNames = (Get-AzureService).ServiceName
    

    The cloud service names are only returned for the current Windows Azure subscription.

    TipTip
    To see a table of cloud services that include existing virtual machines, you can use the Get-AzureVM cmdlet.

  2. Get a list of images that you can use to create the virtual machine.

    PS C:\> $images = Get-AzureVMImage
    

    $images represents a Windows PowerShell list object. You can see the contents of the list by typing $images at the Windows PowerShell command line.

  3. Get the name of the image that you want to use. The image name is a property of the image object in the list of images.

    PS C:\> $myOSImg = $images[3].ImageName
    

    $myOSImg represents the value of the ImageName property from the image that you chose.

    Windows PowerShell starts counting at zero.

  4. Define the name of the cloud service that you want to add the virtual machine to, and define the password of the administrative account for the virtual machine. The cloud service name must be unique.

    PS C:\> $mySvc = $mySvcNames[0]
    
    PS C:\> $myPwd = "P@ssw0rd"
    
  5. Create the virtual machine configuration object and assign it to the variable $VM2.

    PS C:\> $VM2 = New-AzureVMConfig –ImageName $myOSImg –Name "MyVM2" –InstanceSize "Large" –HostCaching "ReadWrite" –DiskLabel "System"
    
  6. Modify the virtual machine object to specify the Windows Server operating system and to set the password for the Administrative account.

    PS C:\> $VM2 = Add-AzureProvisioningConfig –Windows –VM $VM2 –Password $myPwd
    
  7. Create the virtual machine and add it to the existing Windows Azure cloud service.

    PS C:\> New-AzureVM –VM $VM2 –ServiceName $mySvc
    

You can use the New-AzureVM cmdlet to create virtual machines with additional configuration options beyond those covered in this section, including additional storage, networking, authentication and availability options.

Interested in using the Windows Azure Management Portal to do this? See, How to Connect Virtual Machines in a Cloud Service.

Next Steps

Create multiple virtual machines

This section shows you how to create multiple Windows Azure Virtual Machines by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets to create virtual machines in Windows Azure, 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 create a Windows Azure Virtual Machine, you use the Windows Azure cmdlets to define the virtual machine configuration object, and then use the object to create the virtual machine. The New-AzureVM cmdlet supports the -VMs parameter that accepts a list of virtual machine objects. You can use this list to create multiple virtual machines in a single script.

The initial virtual machine objects are created with the New-AzureVMConfig cmdlet. You add more provisioning configuration information to the objects with the Add-AzureProvisioningConfig cmdlet. In this procedure, you create two variables, $VM1 and $VM2, which store the configuration objects for each machine. $VM1 is a Windows virtual machine, and $VM2 is a Linux virtual machine.

Create multiple virtual machines in a single command

Follow these steps to create multiple virtual machines in a single command.

To create multiple virtual machines

  1. Get a list of images that you can use to create the virtual machine.

    PS C:\> $images = Get-AzureVMImage
    

    $images represents a Windows PowerShell list object. You can see the contents of the list by typing $images at the Windows PowerShell command line.

  2. Get the names of the images that you want to use. The image name is a property of the image object in the list of images.

    PS C:\> $myWinImg = $images[3].ImageName
    
    PS C:\> $myLxImg = $images[8].ImageName
    

    $myWinImg represents the value of the ImageName property from the Windows Server image and $myLxImg represents the value of the ImageName property from the Linux image.

    The list of images is subject to change over time, so choose the appropriate images from the current list. The index number for those images might not be the same as shown here. Windows PowerShell starts counting at zero.

  3. Get a list of names of the Windows Azure cloud services that are associated with the current subscription.

    PS C:\> $mySvc = (Get-AzureService).ServiceName
    

    The cloud service names are only returned for the current Windows Azure subscription.

    TipTip
    To see a table of cloud services that include existing virtual machines, you can use the Get-AzureVM cmdlet.

  4. Define the password for the administrative accounts (for simplicity, this example uses the same password for both Linux and Windows), as well as the Linux username for the Linux virtual machine.

    PS C:\> $myPwd = "P@ssw0rd"
    
    PS C:\> $LxUsr = "linuxadmin"
    
  5. Create the virtual machine configuration object.

    PS C:\> $VM1 = New-AzureVMConfig –ImageName $myWinImg –Name "MyUniqueWinVM1" –InstanceSize "Small" –HostCaching "ReadWrite" –DiskLabel "System"
    
    PS C:\> $VM2 = New-AzureVMConfig –ImageName $myLxImg –Name "MyUniqueLxVM2" –InstanceSize "Small" –HostCaching "ReadWrite" –DiskLabel "System"
    
  6. Modify the virtual machine object to specify the operating systems and to set the password for the Administrative accounts.

    PS C:\> $VM1 = Add-AzureProvisioningConfig –Windows –VM $VM1 –Password $myPwd
    
    PS C:\> $VM2 = Add-AzureProvisioningConfig –Linux –VM $VM2 –Password $myPwd -LinuxUser $LxUsr
    
  7. Create the virtual machines.

    PS C:\> New-AzureVM –VMs $VM1,$VM2 –ServiceName $mySvc
    

You can use the New-AzureVM cmdlet to create virtual machines with additional configuration options beyond those covered in this section, including additional storage, networking, authentication and availability options.

Next Steps

Delete a virtual machine

This section shows you how to remove a Windows Azure Virtual Machine from a cloud service by using the following Windows Azure cmdlets:

Prerequisites

Before you can use Windows Azure cmdlets to delete virtual machines in Windows Azure, 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 delete a Windows Azure Virtual Machine by using the Remove-AzureVM cmdlet. This cmdlet removes the virtual machine, but does not delete the VHD(s) associated with it.

Delete a virtual machine

Follow these steps to delete a virtual machine from a cloud service.

To delete a virtual machine

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

    PS C:\> $myVMs = Get-AzureVM
    
  2. Remove the first virtual machine in the list.

    PS C:\> Remove-AzureVM -ServiceName $myVMs[0].ServiceName -Name $myVMs[0].Name
    

Next Steps

  • Remove data disks or VHDs that are associated with the virtual machine. For more information, see Manage Disks and Images.

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