Last active
February 10, 2017 12:29
-
-
Save win2000b/544d6e1fe3a679f7545755d72a0ca236 to your computer and use it in GitHub Desktop.
Create a New Virtual Machine in Azure ARM, Portal. With 2 Network Cards
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
# Login to Azure RM | |
Login-AzureRmAccount | |
# Now we need to select our subscription, To get a list use | |
Get-AzureRmSubscription | |
# Select the subscription with the command | |
Select-AzureRMSubscription -SubscriptionID d411111-1111-2222-3333-0911111951 | |
# Define all our Variables. These resources need to be created prior to the script running. | |
$location = "North Europe" | |
$rgroup = "Servers" | |
$vmname = "EdgeServer" | |
$storage = "EdgeServerStorage" | |
$vnet = "SkypeNetwork" | |
$cred = Get-Credential -Message "Type the name and password of the local administrator account." | |
$WindowsComputerName = "EdgeServer" | |
# Define Size of Virtual Machine needed | |
# A Script to list all virtual machine sizes available in all regions, can be found https://gist.github.com/win2000b/5bccc169f7e66731afce7a586934777f | |
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize "Standard_A3" | |
# Define Size of Virtual Machine OS needed | |
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $WindowsComputerName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate | |
$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest" | |
# Create a new Public IP Address,Change to Static IP if needed. | |
$pip = New-AzureRmPublicIpAddress -Name TestPIP -ResourceGroupName $rgroup -Location $location -AllocationMethod Dynamic | |
# Get details of our VNet. Change the ResourceGroupName to the name of the VNet. To get a list of names use : Get-AzureRmVirtualNetwork | select Name | |
$vnet= Get-AzureRmVirtualNetwork -resourcegroupname Skypedemo | |
# Create 2 Nics, 1 on each subnet retrieved from above | |
$nic1 = New-AzureRmNetworkInterface -Name TestNIC1 -ResourceGroupName $rgroup -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id | |
$nic2 = New-AzureRmNetworkInterface -Name TestNIC2 -ResourceGroupName $rgroup -Location $location -SubnetId $vnet.Subnets[1].Id | |
# Add the Nics to our new VM | |
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic1.Id | |
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic2.Id | |
$vm.NetworkProfile.NetworkInterfaces.Item(0).Primary = $true | |
# If you want the storage account created and not using an existing, uncomment the next line | |
# $storageAcc = New-AzureRmStorageAccount -ResourceGroupName $rgroup -AccountName $storage -Location $location -Type "Standard_LRS" | |
# Get the details of our Storage Account | |
$storageAcc = Get-AzureRMStorageAccount -Name $storage | |
# Define Base OS Disk | |
$osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/WindowsVMosDisk.vhd" | |
# Add the Disk to the VM | |
$vm = Set-AzureRmVMOSDisk -VM $vm -Name “windowsvmosdisk” -VhdUri $osDiskUri -CreateOption fromImage | |
# Finally create the VM | |
New-AzureRmVM -ResourceGroupName $rgroup -Location $location -VM $vm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment