Created
October 25, 2015 19:09
-
-
Save nmackenzie/abaf27af14ec1a81895e to your computer and use it in GitHub Desktop.
Create a single VM using Azure PowerShell v1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is really helpful for me. Thanks for posting it.