Customized Azure VM Image - Powershell

This in continuation of the last post on capturing or customizing image and deploy VM with the help of those images. Below is code that i used to create a customized image. 

First we shutdown the VM and them generalized it and finally created the Image out of it.



$rgName = "RG" 
$vmName = "Test-VM2"
$location = "west us"
$imageName = "testimage"


Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force

Set-AzVm -ResourceGroupName $rgName -Name $vmName -Generalized

$vm = Get-AzVM -Name $vmName -ResourceGroupName $rgName

$image = New-AzImageConfig -Location $location -SourceVirtualMachineId $vm.ID

New-AzImage -Image $image -ImageName $imageName -ResourceGroupName $rgName

No comments:

Post a Comment

The Cost Management Framework

  The Cost Management Framework 🧾 1. Custom Budgeting Strategy What: Define budgets and alerts by business unit, environment (Prod/UAT/...