Azure Image and configuring server with this image
1. Copy the OS disk of the server which you want to take image into a new container of a storage account and in the same container copy other disks of the server which you are taking image through Microsoft Storage Explorer.
2. Copy the URL of the OS disk and data disks into a notepad.
3. Run the following Script in PowerShell, before running the script change the parameter to the required values
Azure PowerShell Script
Login-AzureRmAccount
$subscription = (Get-AzureRmSubscription).SubscriptionName | Out-GridView -Title "Select Azure Subscription" -PassThru
Select-AzureRmSubscription -SubscriptionId "******************************"
$name = "VMName"
$nam = "PIPname"
$vmSize="Standard_F8"
$adminUsername=""
$adminPassword="********"
$sourceImageUri = 'https://sprabstor1.blob.core.windows.net/vhds/sprab007.vhd'
$diskName= $name + "OS-Disk"
$rgName="RGName"
$locName=""
$saName="StorageAccount"
$vnetName="VnetName"
$subnetIndex= '0'
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force)
# Get the existing virtual network
$vnet=Get-AzureRMvirtualNetwork -Name $vnetName -ResourceGroupName $rgName
# Create the NIC
$nicName="NICname"
$pipName= $nam + "_pip"
$domName= $name
$pip=New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -DomainNameLabel $domName -Location $locName -AllocationMethod Dynamic
$nic=New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id
# Specify the name, size
$vmName= $name
$vm=New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
# Specify the local administrator account, and then add the NIC
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Add-AzureRMVMNetworkInterface -VM $vm -Id $nic.Id
$vm=Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred
# Specify the OS disk name
$storageAcc=Get-AzureRMStorageAccount -ResourceGroupName sprabrg -Name $saName
$osDiskUri=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $diskName + ".vhd"
# Create the VM from the captured image
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Set-AzureRMVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $sourceImageUri -Windows
New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm
It will take some time for the server to get deployed after deploying attach the copied data disk of the imaged server to the new server.
1. Copy the OS disk of the server which you want to take image into a new container of a storage account and in the same container copy other disks of the server which you are taking image through Microsoft Storage Explorer.
2. Copy the URL of the OS disk and data disks into a notepad.
3. Run the following Script in PowerShell, before running the script change the parameter to the required values
Azure PowerShell Script
Login-AzureRmAccount
$subscription = (Get-AzureRmSubscription).SubscriptionName | Out-GridView -Title "Select Azure Subscription" -PassThru
Select-AzureRmSubscription -SubscriptionId "******************************"
$name = "VMName"
$nam = "PIPname"
$vmSize="Standard_F8"
$adminUsername=""
$adminPassword="********"
$sourceImageUri = 'https://sprabstor1.blob.core.windows.net/vhds/sprab007.vhd'
$diskName= $name + "OS-Disk"
$rgName="RGName"
$locName=""
$saName="StorageAccount"
$vnetName="VnetName"
$subnetIndex= '0'
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force)
# Get the existing virtual network
$vnet=Get-AzureRMvirtualNetwork -Name $vnetName -ResourceGroupName $rgName
# Create the NIC
$nicName="NICname"
$pipName= $nam + "_pip"
$domName= $name
$pip=New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -DomainNameLabel $domName -Location $locName -AllocationMethod Dynamic
$nic=New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id
# Specify the name, size
$vmName= $name
$vm=New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
# Specify the local administrator account, and then add the NIC
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Add-AzureRMVMNetworkInterface -VM $vm -Id $nic.Id
$vm=Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred
# Specify the OS disk name
$storageAcc=Get-AzureRMStorageAccount -ResourceGroupName sprabrg -Name $saName
$osDiskUri=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $diskName + ".vhd"
# Create the VM from the captured image
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Set-AzureRMVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $sourceImageUri -Windows
New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm
It will take some time for the server to get deployed after deploying attach the copied data disk of the imaged server to the new server.