Deploying an Azure Resource Group (with Resources) for Demo’s


Hello again! I've gotten queries from a few local SI partners regarding a sample PowerShell script that helps to deploy an Azure Resource group with basic resources to showcase automating deployments. Given that some documentation literally goes step-by-step for every action required for deployment with their scripts, this results in some incoherence around what needs to be done and in what sequence.

A great post by Tom FitzMacken outlines the step by step approach with explanations on how to HERE.

The following is a PowerShell script I've put together based in some part on Tom's post.

'Azure Resource Group + Resources Deployment Demo'

'Create a Resource Group'

Login-AzureRmAccount

Get location list

Get-AzureRmLocation | sort Location | Select Location

'variable'

$locname = "southeastasia"

'Create ResourceGroup'

$rgName = "ResourceGroupTest"

New-AzureRmResourceGroup -Name $rgName -Location $locName

'Create Storage Account'

$stName = "resourcestorage0"

Get-AzureRmStorageAccountNameAvailability $stName

$storageAcc = New-AzureRmStorageAccount -ResourceGroupName $rgName -Name $stName -SkuName "Standard_LRS" -Kind "Storage" -Location $locName

'Create Virtual Network'

$subnetName = "ResourceSubnet"

$singleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24

'Create VNet'

$vnetName = "ResourceVnet0"

$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $locName -AddressPrefix 10.0.0.0/16 -Subnet $singleSubnet

'Create Public IP and Network Interface'

$ipName = "ResourceIP0"

$pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic

'NIC Name'

$nicName = "ResourceNIC0"

$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id

'Create VM

Set Admin UName & PWD'

$cred = Get-Credential -Message "ResourceAdmin Pass@word1!@"

'Create VM'

$vmName = "resourceprodvm0"

$vm = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A4"

'Define the Image to use'

$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"

'Add NIC Interface'

$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

'Add DiskPath & Create VHD'

$blobPath = "vhds/WindowsVMosDisk.vhd"

$osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + $blobPath

'Name OS Disk'

$diskName = "ResourceVMosDisk"

$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows

$vm = Set-AzureRmVMosDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage

'Finally Create the VM in Azure'

New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm

This script will do the following:

  1. Ask you to login to your Azure Subscription
  2. Set Deployment location to the SoutheastAsia Region
  3. Create a Resource Group with the following attributes provisioned: Storage Account, Virtual Network (with Subnet), Create Public IP with vNIC assigned, Create VM (With Username & Password prompted for on the pop-up), Add a NIC INterface, Add DiskPath and Create VHD, Name the OS disk.
  4. Create the actual VM itself (Predefined to a Standard_A4 VM). The script will in the end prompt you to name the VM (Name provided in the script body, or you can use your own)

Hope this helps you folks with your demo deployments!

Cheers,

Abhishek

Comments (0)

Skip to main content