-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-snapshot-to-same-or-different-subscription.ps1
30 lines (21 loc) · 1.39 KB
/
copy-snapshot-to-same-or-different-subscription.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Provide the subscription Id of the subscription where snapshot exists
$sourceSubscriptionId='dd80b94e-0463-4a65-8d04-c94f403879dc'
#Provide the name of your resource group where snapshot exists
$sourceResourceGroupName='myResourceGroupName'
#Provide the name of the snapshot
$snapshotName='mySnapshotName'
#Set the context to the subscription Id where snapshot exists
Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId
#Get the source snapshot
$snapshot= Get-AzureRmSnapshot -ResourceGroupName $sourceResourceGroupName -Name $snapshotName
#Provide the subscription Id of the subscription where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
$targetSubscriptionId='6492b1f7-f219-446b-b509-314e17e1efb0'
#Name of the resource group where snapshot will be copied to
$targetResourceGroupName='myTargetResourceGroupName'
#Set the context to the subscription Id where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId
$snapshotConfig = New-AzureRmSnapshotConfig -SourceResourceId $snapshot.Id -Location $snapshot.Location -CreateOption Copy
#Create a new snapshot in the target subscription and resource group
New-AzureRmSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotName -ResourceGroupName $targetResourceGroupName