Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 6b93e1b

Browse files
authored
Update create-managed-disks-from-vhd-in-different-subscription.ps1 (#388)
* Update create-managed-disks-from-vhd-in-different-subscription.ps1 * Update virtual-machine/create-managed-disks-from-vhd-in-different-subscription/create-managed-disks-from-vhd-in-different-subscription.ps1
1 parent 4fe2eff commit 6b93e1b

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
#Provide the subscription Id where Managed Disks will be created
1+
2+
<#
3+
4+
.DESCRIPTION
5+
6+
This sample demonstrates how to create a Managed Disk from a VHD file.
7+
Create Managed Disks from VHD files in following scenarios:
8+
1. Create a Managed OS Disk from a specialized VHD file. A specialized VHD is a copy of VHD from an exisitng VM that maintains the user accounts, applications and other state data from your original VM.
9+
Attach this Managed Disk as OS disk to create a new virtual machine.
10+
2. Create a Managed data Disk from a VHD file. Attach the Managed Disk to an existing VM or attach it as data disk to create a new virtual machine.
11+
12+
.NOTES
13+
14+
1. Before you use this sample, please install the latest version of Azure PowerShell from here: http://go.microsoft.com/?linkid=9811175&clcid=0x409
15+
2. Provide the appropriate values for each variable. Note: The angled brackets should not be included in the values you provide.
16+
17+
18+
#>
19+
20+
#Provide the subscription Id
221
$subscriptionId = 'yourSubscriptionId'
322

4-
#Provide the name of your resource group where Managed Disks will be created.
23+
#Provide the name of your resource group
524
$resourceGroupName ='yourResourceGroupName'
625

726
#Provide the name of the Managed Disk
@@ -10,28 +29,31 @@ $diskName = 'yourDiskName'
1029
#Provide the size of the disks in GB. It should be greater than the VHD file size.
1130
$diskSize = '128'
1231

13-
#Provide the storage type for Managed Disk. Premium_LRS or Standard_LRS.
14-
$storageType = 'Premium_LRS'
32+
#Provide the URI of the VHD file that will be used to create Managed Disk.
33+
# VHD file can be deleted as soon as Managed Disk is created.
34+
# e.g. https://contosostorageaccount1.blob.core.windows.net/vhds/contoso-um-vm120170302230408.vhd
35+
$vhdUri = 'https://contosoststorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd'
36+
37+
#Provide the storage type for the Managed Disk. PremiumLRS or StandardLRS.
38+
$sku = 'PremiumLRS'
1539

16-
#Provide the Azure region (e.g. westus) where Managed Disk will be located.
17-
#This location should be same as the storage account where VHD file is stored
40+
#Provide the Azure location (e.g. westus) where Managed Disk will be located.
41+
#The location should be same as the location of the storage account where VHD file is stored.
1842
#Get all the Azure location using command below:
19-
#Get-AzLocation
43+
#Get-AzureRmLocation
2044
$location = 'westus'
2145

22-
#Provide the URI of the VHD file (page blob) in a storage account. Please not that this is NOT the SAS URI of the storage container where VHD file is stored.
23-
#e.g. https://contosostorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd
24-
#Note: VHD file can be deleted as soon as Managed Disk is created.
25-
$sourceVHDURI = 'https://contosostorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd'
26-
27-
#Provide the resource Id of the storage account where VHD file is stored.
28-
#e.g. /subscriptions/6472s1g8-h217-446b-b509-314e17e1efb0/resourceGroups/MDDemo/providers/Microsoft.Storage/storageAccounts/contosostorageaccount
29-
#This is an optional parameter if you are creating managed disk in the same subscription
30-
$storageAccountId = '/subscriptions/yourSubscriptionId/resourceGroups/yourResourceGroupName/providers/Microsoft.Storage/storageAccounts/yourStorageAccountName'
31-
3246
#Set the context to the subscription Id where Managed Disk will be created
33-
Select-AzSubscription -SubscriptionId $SubscriptionId
47+
Set-AzContext -Subscription $subscriptionId
48+
49+
#If you're creating an OS disk, add the following lines
50+
#Acceptable values are either Windows or Linux
51+
#$OSType = 'yourOSType'
52+
#Acceptable values are either V1 or V2
53+
#$HyperVGeneration = 'yourHyperVGen'
3454

35-
$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI -OsType $OsType -DiskSizeGB $diskSize
55+
#If you're creating an OS disk, add -HyperVGeneration and -OSType parameters
56+
$diskConfig = New-AzDiskConfig -SkuName $sku -Location $location -DiskSizeGB $diskSize -SourceUri $vhdUri -CreateOption Import
3657

37-
New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName
58+
#Create Managed disk
59+
New-AzDisk -DiskName $diskName -Disk $diskConfig -ResourceGroupName $resourceGroupName

0 commit comments

Comments
 (0)