Create a custom VM into Existing Resource Group using Azure RM PowerShell


#Install Azure RM module if missing and Login to Azure

Install-Module -name AzureRM -AllowClobber

Login-AzureRmAccount

Get-AzureRmSubscription

 

#Set Variables

$subscriptionId =  'd855443e-XXXX-4a82-9a63-XXXXXXXXXXXX

$storageAccountName = 'YourStorageAccountName'

$sourceImageUri = https://YourStorageAccountName.blob.core.windows.net/vhds/YourUploadedVHDName.vhd'

 

$resourceGroupName     = "YourResourceGroupName"

$locationName          = "YourLocationName"                                    => Ex) Japan East

$vnetName              = "YourExistingVirtualNetworkName"

$vmnetinf              = "YourNewNetworkInterfaceName"

$backendSubnetName     = "YourExistingSubNetName"

$remoteAccessNSGName   = "YourNewNSGName "

$vmname                = "YourNewVMName"

$vmSize                = "YourNewVMSize"                                               => Ex) Standard_D1

$osDiskName            = $vmname+'_osDisk'

 

$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $vnetName

 

$publicIp = New-AzureRmPublicIpAddress -Name $vmname -ResourceGroupName $ResourceGroupName -Location $locationName -AllocationMethod Dynamic

$networkInterface = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name $vmnetinf -Location $locationName -SubnetId $virtualNetwork.Subnets[0].Id -PublicIpAddressId $publicIp.Id

 

$vmConfig = New-AzureRmVMConfig -VMName $vmname -VMSize $vmSize

$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $osDiskName -VhdUri $sourceImageUri -CreateOption Attach -Windows

$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $networkInterface.Id

 

$vm = New-AzureRmVM -VM $vmConfig -Location $locationName -ResourceGroupName $resourceGroupName


Comments (0)

Skip to main content