Created
September 2, 2015 15:03
-
-
Save bblanchon/810370aebd9989417fef to your computer and use it in GitHub Desktop.
Azure: Capture a VM
This file contains hidden or 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
$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