New-AzureRmVM

Creates a virtual machine.

Syntax

New-AzureRmVM
   [[-ResourceGroupName] <String>]
   [[-Location] <String>]
   -Name <String>
   -Credential <PSCredential>
   [-VirtualNetworkName <String>]
   [-AddressPrefix <String>]
   [-SubnetName <String>]
   [-SubnetAddressPrefix <String>]
   [-PublicIpAddressName <String>]
   [-DomainNameLabel <String>]
   [-AllocationMethod <String>]
   [-SecurityGroupName <String>]
   [-OpenPorts <Int32[]>]
   [-ImageName <String>]
   [-Size <String>]
   [-AvailabilitySetName <String>]
   [-AsJob]
   [-DataDiskSizeInGb <Int32[]>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzureRmVM
   [-ResourceGroupName] <String>
   [-Location] <String>
   [-VM] <PSVirtualMachine>
   [[-Zone] <String[]>]
   [-DisableBginfoExtension]
   [-Tag <Hashtable>]
   [-LicenseType <String>]
   [-AsJob]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzureRmVM
   [[-ResourceGroupName] <String>]
   [[-Location] <String>]
   -Name <String>
   [-VirtualNetworkName <String>]
   [-AddressPrefix <String>]
   [-SubnetName <String>]
   [-SubnetAddressPrefix <String>]
   [-PublicIpAddressName <String>]
   [-DomainNameLabel <String>]
   [-AllocationMethod <String>]
   [-SecurityGroupName <String>]
   [-OpenPorts <Int32[]>]
   -DiskFile <String>
   [-Linux]
   [-Size <String>]
   [-AvailabilitySetName <String>]
   [-AsJob]
   [-DataDiskSizeInGb <Int32[]>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The New-AzureRmVM cmdlet creates a virtual machine in Azure. This cmdlet takes a virtual machine object as input. Use the New-AzureRmVMConfig cmdlet to create a virtual machine object. Other cmdlets can be used to configure the virtual machine, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, Add-AzureRmVMNetworkInterface, and Set-AzureRmVMOSDisk.

The SimpleParameterSet provides a convenient method to create a VM by making common VM creation arguments optional.

Examples

Example 1: Create a virtual machine

PS C:\> New-AzureRmVM -Name MyVm -Credential (Get-Credential)

VERBOSE: Use 'mstsc /v:myvm-222222.eastus.cloudapp.azure.com' to connect to the VM.

ResourceGroupName        : MyVm
Id                       : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyVm/provi
ders/Microsoft.Compute/virtualMachines/MyVm
VmId                     : 11111111-1111-1111-1111-111111111111
Name                     : MyVm
Type                     : Microsoft.Compute/virtualMachines
Location                 : eastus
Tags                     : {}
HardwareProfile          : {VmSize}
NetworkProfile           : {NetworkInterfaces}
OSProfile                : {ComputerName, AdminUsername, WindowsConfiguration, Secrets}
ProvisioningState        : Succeeded
StorageProfile           : {ImageReference, OsDisk, DataDisks}
FullyQualifiedDomainName : myvm-222222.eastus.cloudapp.azure.com

This example script shows how to create a virtual machine. The script will ask a user name and password for the VM. This script uses several other cmdlets.

Example 2: Create a virtual machine from a custom user image

PS C:\> ## VM Account
# Credentials for Local Admin account you created in the sysprepped (generalized) vhd image
$VMLocalAdminUser = "LocalAdminUser"
$VMLocalAdminSecurePassword = ConvertTo-SecureString "Password" -AsPlainText -Force
## Azure Account
$LocationName = "westus"
$ResourceGroupName = "MyResourceGroup"
# This a Premium_LRS storage account.
# It is required in order to run a client VM with efficiency and high performance.
$StorageAccount = "Mydisk"

## VM
$OSDiskName = "MyClient"
$ComputerName = "MyClientVM"
$OSDiskUri = "https://Mydisk.blob.core.windows.net/disks/MyOSDisk.vhd"
$SourceImageUri = "https://Mydisk.blob.core.windows.net/vhds/MyOSImage.vhd"
$VMName = "MyVM"
# Modern hardware environment with fast disk, high IOPs performance.
# Required to run a client VM with efficiency and performance
$VMSize = "Standard_DS3"
$OSDiskCaching = "ReadWrite"
$OSCreateOption = "FromImage"

## Networking
$DNSNameLabel = "mydnsname" # mydnsname.westus.cloudapp.azure.com
$NetworkName = "MyNet"
$NICName = "MyNIC"
$PublicIPAddressName = "MyPIP"
$SubnetName = "MySubnet"
$SubnetAddressPrefix = "10.0.0.0/24"
$VnetAddressPrefix = "10.0.0.0/16"

$SingleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
$Vnet = New-AzureRmVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroupName -Location $LocationName -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet
$PIP = New-AzureRmPublicIpAddress -Name $PublicIPAddressName -DomainNameLabel $DNSNameLabel -ResourceGroupName $ResourceGroupName -Location $LocationName -AllocationMethod Dynamic
$NIC = New-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroupName -Location $LocationName -SubnetId $Vnet.Subnets[0].Id -PublicIpAddressId $PIP.Id

$Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword);

$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -SourceImageUri $SourceImageUri -Caching $OSDiskCaching -CreateOption $OSCreateOption -Windows

New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

This example takes an existing sys-prepped, generalized custom operating system image and attaches a data disk to it, provisions a new network, deploys the VHD, and runs it.

This script can be used for automatic provisioning because it uses the local virtual machine admin credentials inline instead of calling Get-Credential which requires user interaction.

This script assumes that you are already logged into your Azure account. You can confirm your login status by using the Get-AzureSubscription cmdlet.

Required Parameters

-Credential

The administrator credentials for the VM.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DiskFile

The local path to the virtual hard disk file to be uploaded to the cloud and for creating the VM, and it must have '.vhd' as its suffix.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Name

The name of the VM resource.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-VM

Specifies a local virtual machine to create. To obtain a virtual machine object, use the New-AzureRmVMConfig cmdlet. Other cmdlets can be used to configure the virtual machine, such as Set-AzureRmVMOperatingSystem, Set-AzureRmVMSourceImage, and Add-AzureRmVMNetworkInterface.

Type:PSVirtualMachine
Aliases:VMProfile
Position:2
Default value:None
Accept pipeline input:True (ByPropertyName, ByValue)
Accept wildcard characters:False

Optional Parameters

-AddressPrefix

The address prefix for the virtual network which will be created for the VM.

Type:String
Position:Named
Default value:192.168.0.0/16
Accept pipeline input:False
Accept wildcard characters:False
-AllocationMethod

The IP allocation method for the public IP which will be created for the VM.

Type:String
Parameter Sets:Static, Dynamic
Position:Named
Default value:Static
Accept pipeline input:False
Accept wildcard characters:False
-AsJob

Run cmdlet in the background and return a Job to track progress.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AvailabilitySetName

Specifies a name for the availability set.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-DataDiskSizeInGb

Specifies the sizes of data disks in GB.

Type:Int32[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DisableBginfoExtension

Indicates that this cmdlet does not install the BG Info extension on the virtual machine.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DomainNameLabel

The subdomain label for the fully-qualified domain name (FQDN) of the VM. This will take the form {domainNameLabel}.{location}.cloudapp.azure.com.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ImageName

The friendly image name upon which the VM will be built. These include: Win2016Datacenter, Win2012R2Datacenter, Win2012Datacenter, Win2008R2SP1, UbuntuLTS, CentOS, CoreOS, Debian, openSUSE-Leap, RHEL, SLES.

Type:String
Position:Named
Default value:Win2016Datacenter
Accept pipeline input:False
Accept wildcard characters:False
-LicenseType

Specifies a license type, which indicates that the image or disk for the virtual machine was licensed on-premises. This value is used only for images that contain the Windows Server operating system. The acceptable values for this parameter are:

  • Windows_Client
  • Windows_Server

This value cannot be updated. If you specify this parameter for an update, the value must match the initial value for the virtual machine.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Linux

Indicates whether the disk file is for Linux VM, if specified; or Windows, if not specified by default.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Location

Specifies a location for the virtual machine.

Type:String
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-OpenPorts

A list of ports to open on the network security group (NSG) for the created VM. The default value depends on the type of image chosen (i.e., Windows: 3389, 5985 and Linux: 22).

Type:Int32[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-PublicIpAddressName

The name of a new (or existing) public IP address for the created VM to use. If not specified, a name will be generated.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ResourceGroupName

Specifies the name of a resource group.

Type:String
Position:0
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-SecurityGroupName

The name of a new (or existing) network security group (NSG) for the created VM to use. If not specified, a name will be generated.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Size

The Virtual Machine Size. The Default Value is: Standard_DS1_v2.

Type:String
Position:Named
Default value:Standard_DS1_v2
Accept pipeline input:False
Accept wildcard characters:False
-SubnetAddressPrefix

The address prefix for the subnet which will be created for the VM.

Type:String
Position:Named
Default value:192.168.1.0/24
Accept pipeline input:False
Accept wildcard characters:False
-SubnetName

The name of a new (or existing) subnet for the created VM to use. If not specified, a name will be generated.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Tag

Specifies that resources and resource groups can be tagged with a set of name-value pairs. Adding tags to resources enables you to group resources together across resource groups and to create your own views. Each resource or resource group can have a maximum of 15 tags.

Type:Hashtable
Aliases:Tags
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-VirtualNetworkName

The name of a new (or existing) virtual network for the created VM to use. If not specified, a name will be generated.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs.

The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-Zone

Specifies the zone list of the virtual machine.

Type:String[]
Position:3
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Inputs

PSVirtualMachine

Parameter 'VM' accepts value of type 'PSVirtualMachine' from the pipeline

Outputs

Microsoft.Azure.Commands.Compute.Models.PSAzureOperationResponse