Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

New-AzureVM

New-AzureVM

microsoft.azure.commands.compute.dll, microsoft.windowsazure.commands.servicemanagement.dll

Synopsis

Create a new VM

Syntax

New-AzureVM [-ResourceGroupName] [-Location] [-VM] [-Name] [-Tags] [-Profile] [-InformationAction] [-InformationVariable] [<CommonParameters>]

Detailed Description

This cmdlet allows you to create a new VM in Azure. This cmdlet takes a VM object as input which can be created using the New-AzureVMConfig cmdlet. The VM object must then be configured correctly using appropriate cmdlets such as Set-AzureVMOperatingSystem, Set-AzureVMSourceImage, Set-AzureVMNetworkInterface etc. before the VM can be created in Azure succesfully.

Parameters

-ResourceGroupName <String>

Name of the Resource Group

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Location <String>

Location of the VM

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-VM <PSVirtualMachine>

VM object that is configured and represents the state of the VM to be created. The VM object can be created using the New-AzureVMConfig cmdlet. The VM object must then be configured correctly using appropriate cmdlets such as Set-AzureVMOperatingSystem, Set-AzureVMSourceImage, Set-AzureVMNetworkInterface etc. before the VM can be created in Azure succesfully.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByValue, ByPropertyName)

Accept wildcard characters?

false

-Name <String>

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Tags <Hashtable[]>

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Profile <AzureProfile>

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

false

Accept wildcard characters?

false

-InformationAction <ActionPreference>

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

false

Accept wildcard characters?

false

-InformationVariable <String>

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

false

Accept wildcard characters?

false

Input Type


Return Type


Notes

Examples

-------------------------- Create a VM with two Data Disks --------------------------

PS C:\> # Common
          $rgname = "myrg"
          $loc = 'West US';
          $vmsize = 'Standard_A2';
          $vmname = 'vm' + $rgname;

          # Create Resource Group
          New-AzureResourceGroup -Name $rgname -Location $loc;

          # Create VM Object
          $vm = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;

          # Setup Networking
          $subnet = New-AzureVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24" -DnsServer "10.1.1.1";
          $vnet = New-AzureVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
          $vnet = Get-AzureVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
          $subnetId = $vnet.Properties.Subnets[0].Id;
          $pubip = New-AzurePublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
          $pubip = Get-AzurePublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
          $pubipId = $pubip.Id;
          $nic = New-AzureNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic  -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
          $nic = Get-AzureNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
          $nicId = $nic.Id;

          # Add NIC to VM
          $vm = Add-AzureVMNetworkInterface -VM $vm -Id $nicId;

          # Setup Storage
          $stoname = 'sto' + $rgname;
          $stotype = 'Standard_GRS';

          New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
          $stoaccount = Get-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname;

          $osDiskName = 'osDisk';
          $osDiskCaching = 'ReadWrite';
          $osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
          $dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
          $dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";

          # Add Data Disks
          $vm = Add-AzureVMDataDisk -VM $vm -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1;
          $vm = Add-AzureVMDataDisk -VM $vm -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2;

          # Setup OS & Image
          $user = "Foo12";
          $password = 'BaR@123' + $rgname;
          $securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
          $cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);

          $computerName = 'test';
          $vhdContainer = "https://$stoname.blob.core.windows.net/test";
          $img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201410.01-en.us-127GB.vhd';

          $vm = Set-AzureVMOperatingSystem -VM $vm -Windows -ComputerName $computerName -Credential $cred;
          $vm = Set-AzureVMSourceImage -VM $vm -Name $img -DestinationVhdsContainer $vhdContainer;

          # Create Virtual Machine
          New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $vm;