Skip to content

Instantly share code, notes, and snippets.

@nmackenzie
Created October 25, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmackenzie/abaf27af14ec1a81895e to your computer and use it in GitHub Desktop.
Save nmackenzie/abaf27af14ec1a81895e to your computer and use it in GitHub Desktop.
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
Copy link

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