New-AzureVM
New-AzureVM
Creates a virtual machine.
Syntax
Parameter Set: Default
New-AzureVM -Location <String> -ResourceGroupName <String> -VM <PSVirtualMachine> [-Name <String> ] [-Profile <AzureProfile> ] [-Tags <System.Collections.Hashtable[]> ] [ <CommonParameters>]
Detailed Description
The New-AzureVM cmdlet creates a virtual machine in Azure. This cmdlet takes a virtual machine object as input. Use the New-AzureVMConfig cmdlet to create a virtual machine object. Configure the virtual machine object by using other cmdlets, such as Set-AzureVMOperatingSystem, Set-AzureVMSourceImage, Add-AzureVMNetworkInterface, and Set-AzureVMOSDisk.
Parameters
-Location<String>
Specifies a location for the virtual machine.
Aliases |
none |
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
-Name<String>
Specifies a name for the virtual machine.
Aliases |
ResourceName,VMName |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
-Profile<AzureProfile>
Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-ResourceGroupName<String>
Specifies the name of a resource group.
Aliases |
none |
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
-Tags<System.Collections.Hashtable[]>
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
-VM<PSVirtualMachine>
Specifies a local virtual machine to create. To obtain a virtual machine object, use the New-AzureVMConfig cmdlet. Configure the virtual machine by using other cmdlets, such as Set-AzureVMOperatingSystem, Set-AzureVMSourceImage, and Add-AzureVMNetworkInterface.
Aliases |
VMProfile |
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true(ByValue,ByPropertyName) |
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
Outputs
The output type is the type of the objects that the cmdlet emits.
Examples
Example 1: Create a virtual machine
This example script shows how to create a virtual machine. This script uses several other cmdlets.
# Variables
## Global
$ResourceGroupName = "ResourceGroup11"
$Location = "westeurope"
## Storage
$StorageName = "GeneralStorage6cc"
$StorageType = "Standard_GRS"
## Network
$InterfaceName = "ServerInterface06"
$Subnet1Name = "Subnet1"
$VNetName = "VNet09"
$VNetAddressPrefix = "10.0.0.0/16"
$VNetSubnetAddressPrefix = "10.0.0.0/24"
## Compute
$VMName = "VirtualMachine12"
$ComputerName = "Server22"
$VMSize = "Standard_A2"
$OSDiskName = $VMName + "osDisk"
# Resource Group
New-AzureResourceGroup -Name $ResourceGroupName -Location $Location
# Storage
$StorageAccount = New-AzureStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location
# Network
$PIp = New-AzurePublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic
$SubnetConfig = New-AzureVirtualNetworkSubnetConfig -Name $Subnet1Name -AddressPrefix $VNetSubnetAddressPrefix
$VNet = New-AzureVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig
$Interface = New-AzureNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp.Id
# Compute
## Setup local VM object
$Credential = Get-Credential
$VirtualMachine = New-AzureVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate
$VirtualMachine = Set-AzureVMSourceImage -VM $VirtualMachine -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
$VirtualMachine = Add-AzureVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd"
$VirtualMachine = Set-AzureVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage
## Create the VM in Azure
New-AzureVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine