1

i am trying to copy azure captured image from one subscription-another subscription currently in portal move is coming soon so i am trying to copy it and searching for some power shell script i don't want to create a vm from that with out creating vm i am trying to copy

it is managed disk through power shell i can copy managed disk from one subscription-another by creating vm from it but i am trying without creating vm i am trying copy or move capture image is this possible with power shell can any have idea about this.?

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
luckygiri
  • 63
  • 2
  • 9

1 Answers1

2

i am trying copy or move capture image is this possible with power shell can any have idea about this.?

No, it is not possible. Image does not copy from one subscription to another subscription. You need copy image's managed disk to other subscription.

You have two option.

1.Using image's managed to create a snapshot and copy this snapshot to other subscription, then using this snapshot to create a managed disk, then create a image.

#Create a snapshot from managed disk
$disk = "/subscriptions/************/resourceGroups/SHUICLI/providers/Microsoft.Compute/disks/shui_OsDisk_1_21af43450987448184b5e9793da08e54"
$snapshot = New-AzureRmSnapshotConfig -SourceUri $disk.Id -CreateOption Copy -Location $region
$snapshotName = $imageName + "-" + $region + "-snap"
New-AzureRmSnapshot -ResourceGroupName $resourceGroupName -Snapshot $snapshot -SnapshotName $snapshotName

#copy the snapshot to another subscription, same region
$snap = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName

#change to the target subscription
Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId
$snapshotConfig = New-AzureRmSnapshotConfig -OsType Windows `
                                            -Location $region `
                                            -CreateOption Copy `
                                            -SourceResourceId $snap.Id
$snap = New-AzureRmSnapshot -ResourceGroupName $resourceGroupName `
                            -SnapshotName $snapshotName `
                            -Snapshot $snapshotConfig

More information about this please refer to this blog.

2.Copy image's managed disk to a storage account, then using this VHD to create a new image.

##create $SAS
$sas = Grant-AzureRmDiskAccess -ResourceGroupName shui -DiskName shuitest -DurationInSecond 3600 -Access Read 
$destContext = New-AzureStorageContext –StorageAccountName contosostorageav1 -StorageAccountKey 'YourStorageAccountKey' 
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd'

See this answer.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45