Last active
February 23, 2017 14:22
-
-
Save marrobi/5af68ab6d5a69357555c280becb637c5 to your computer and use it in GitHub Desktop.
Capture VM Image
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
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