Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a single VM using Azure PowerShell v1
$testName = "lower-case-unique-name"
$resourceGroupName = $testName
$location = "westus"
$publisher = "MicrosoftWindowsServer"
$offer = "WindowsServer"
$sku = "2012-R2-Datacenter"
$version = "latest"
$subnetName = "Subnet-1"
$cred = Get-Credential
New-AzureRmResourceGroup -Name $resourceGroupName -Location $location
New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName `
-Name $testName -Location $location -Type Standard_LRS
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName `
-AddressPrefix "10.0.64.0/24"
$vnet = New-AzureRmVirtualNetwork -Name "VNET" `
-ResourceGroupName $resourceGroupName `
-Location $location -AddressPrefix "10.0.0.0/16" -Subnet $subnet
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Name "vip1" `
-Location $location -AllocationMethod Dynamic -DomainNameLabel $testName
$nic = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
-Name "nic1" -Subnet $subnet -Location $location -PublicIpAddress $pip -PrivateIpAddress "10.0.64.4"
$vmConfig = New-AzureRmVMConfig -VMName "$testName-w1" -VMSize "Standard_A1" |
Set-AzureRmVMOperatingSystem -Windows -ComputerName "$testName-w1" `
-Credential $cred -ProvisionVMAgent -EnableAutoUpdate |
Set-AzureRmVMSourceImage -PublisherName $publisher -Offer $offer -Skus $sku `
-Version $version |
Set-AzureRmVMOSDisk -Name "$testName-w1" -VhdUri "https://$testName.blob.core.windows.net/vhds/$testName-w1-os.vhd" `
-Caching ReadWrite -CreateOption fromImage |
Add-AzureRmVMNetworkInterface -Id $nic.Id
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location `
-VM $vmConfig
(Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName).IpAddress
Get-AzureRmResource -ResourceGroupName $resourceGroupName | Select Name, ResourceType
@AndrewShepherd

This comment has been minimized.

Copy link

commented Jun 21, 2016

This is really helpful for me. Thanks for posting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.