If you want to create an image from you existing VM in
azure. First thing you need to do is Login to you VM and syspre it.
Normally we need to create multiple copies of same set of
installed softwares and other system setting we do imaging. Your first VM will
be your model image for all VMs which you will be creating using one image.
Sysprep
Go to RUN type “Sysprep” without quotation.
Double click on sysprep.
Make sure Enter System
Out-of-Box Experience (OOBE) Selected Generalize
Check box checked and Shutdown option is selected. As mentioned above.
This will Clear all you SIDs and generalize your system and
shutdown the VM.
Note: Once the system shutdown you can’t use it again that
VM.
Now Open your Powershell ISE in Administrator mode. And past
the below command.
Modify according to yourself in Global Variable session.
################################# Start####################################
#
Capture VM from existing syspreped vm.
#
Sign-in with Azure account credentials
Login-AzureRmAccount
#
Select your Azure Subscription.
$subscriptionId
=
(Get-AzureRmSubscription |
Out-GridView `
-Title "Select an Azure
Subscription ..." `
-PassThru).SubscriptionId
Select-AzureRmSubscription
`
-SubscriptionId $subscriptionId
# Global Variables.
#Give
resource grou name where your sysprep VM reside.
$ResourceGroupName
= "srcresourcegrp"
##
Computer
#Give
your sysprep VM Name.
$vmName
= "srcvm"
#Give
Container Name where your image will be storing. any name you can give it will
create its own.
$continerName
= "customvhd"
#######################################################################################
#
Deallocate the virtual machine
Stop-AzureRmVM
-ResourceGroupName $ResourceGroupName -Name $vmName
#
Set the Generalized state to the virtual machine
Set-AzureRmVm
-ResourceGroupName $ResourceGroupName -Name $vmName -Generalized
#
Check the status.
$vm
= Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $vmName -status
$vm.Statuses
#
Now capture the VM.
Save-AzureRmVMImage
-ResourceGroupName $ResourceGroupName -VMName $vmName -DestinationContainerName
$continerName -VHDNamePrefix 'Captured image' -Path C:\srcvm.json
################################### End
#####################################
No comments:
Post a Comment