Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created September 2, 2015 15:03
Show Gist options
  • Save bblanchon/810370aebd9989417fef to your computer and use it in GitHub Desktop.
Save bblanchon/810370aebd9989417fef to your computer and use it in GitHub Desktop.
Azure: Capture a VM
$ErrorActionPreference = "Stop"
Add-AzureAccount
Select-AzureSubscription -Name "Continuous Integration"
Write-Host 'The following VM instances are available:'
Get-AzureVM | foreach { $_.Name }
$vmName = Read-Host 'Enter the name of the VM to capture'
Write-Host 'The following VM images are available:'
Get-AzureVMImage | Where { $_.Category -eq "User" } | foreach { $_.ImageName }
$imageName = Read-Host 'Enter the name of the VM image to create'
$imageDesc = Read-Host 'Enter the description of the VM image'
$vm = Get-AzureVM | where { $_.Name -eq $vmName }
$vm | Stop-AzureVM -Verbose -Force
$vm | Save-AzureVMImage -ImageName $imageName -ImageLabel $imageDesc -OSState Specialized -Verbose
$vm | Remove-AzureVM -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment