Created
June 20, 2019 13:16
-
-
Save joostmeijles/09cc065b98bd1e7c1ef44ed7939152ae to your computer and use it in GitHub Desktop.
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
# Prepare the VM parameters | |
$rgName = "<region name>" | |
$location = "westeurope" | |
# Copy subnet link from Azure Portal URL | |
$subnet = "/subscriptions/xxxxxxxxx/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<virtual-network>/subnets/<subnet>" | |
$nicName = "<NIC name>" | |
$vmName = "<VM name>" | |
$osDiskName = "$vmName-OSDisk" | |
# Copy disk URI from Azure Portal | |
$osDiskUri = "<disk uri>" | |
$VMSize = "Standard_DS3_v2" | |
$storageAccountType = "StandardSSD_LRS" | |
$IPaddress = "10.0.0.6" # Internal ip | |
# Create the VM resources | |
$IPconfig = New-AzureRmNetworkInterfaceIpConfig -Name "IPConfig1" -PrivateIpAddressVersion IPv4 -SubnetId $subnet -PrivateIpAddress $IPaddress | |
# NIC with only private ip, add a dynamic ip and DNS name afterwards in the Azure Portal | |
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -IpConfiguration $IPconfig | |
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $VMSize | |
$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id | |
$osDisk = New-AzureRmDisk -DiskName $osDiskName -Disk (New-AzureRmDiskConfig -AccountType $storageAccountType -Location $location -CreateOption Import -SourceUri $osDiskUri) -ResourceGroupName $rgName | |
$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType $storageAccountType -DiskSizeInGB 128 -CreateOption Attach -Windows | |
$vm = Set-AzureRmVMBootDiagnostics -VM $vm -disable | |
#Create the new VM | |
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment