Skip to content

Instantly share code, notes, and snippets.

@marrobi
Last active February 23, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marrobi/5af68ab6d5a69357555c280becb637c5 to your computer and use it in GitHub Desktop.
Save marrobi/5af68ab6d5a69357555c280becb637c5 to your computer and use it in GitHub Desktop.
Capture VM Image
Param
(
[Parameter(Mandatory=$true)]
$VMResourceGroupName,
[Parameter(Mandatory=$true)]
$ImageResourceGroupName,
[Parameter(Mandatory=$true)]
$VMName,
[Parameter(Mandatory=$true)]
$ImageName,
[Parameter(Mandatory=$true)]
$Region
)
Stop-AzureRmVM -ResourceGroupName $VMResourceGroupName -Name $VMName -Force
Set-AzureRmVm -ResourceGroupName $VMResourceGroupName -Name $VMName -Generalized
$vm = Get-AzureRmVM -Name $VMName -ResourceGroupName $VMResourceGroupName
$image = New-AzureRmImageConfig -Location $Region -SourceVirtualMachineId $vm.ID
New-AzureRmImage -Image $image -ImageName $imageName -ResourceGroupName $ImageResourceGroupName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment