Skip to content

Commit 36d5761

Browse files
committed
revised PS script hardcoded in
1 parent d9a9f4e commit 36d5761

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

articles/virtual-machines/scripts/virtual-machines-powershell-sample-create-managed-disk-from-vhd.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ manager: kavithag
66
ms.service: virtual-machines
77
ms.topic: sample
88
ms.custom: devx-track-azurepowershell
9-
ms.date: 12/04/2023
9+
ms.date: 07/01/2024
1010
ms.author: ramankum
1111
---
1212

@@ -18,13 +18,73 @@ Don't create multiple identical managed disks from a VHD file in small amount of
1818

1919
[!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
2020

21+
## Sample script
2122

22-
23+
```powershell
2324
24-
## Sample script
25+
<#
26+
27+
.DESCRIPTION
28+
29+
This sample demonstrates how to create a Managed Disk from a VHD file.
30+
Create Managed Disks from VHD files in following scenarios:
31+
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.
32+
Attach this Managed Disk as OS disk to create a new virtual machine.
33+
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.
34+
35+
.NOTES
36+
37+
1. Before you use this sample, please install the latest version of Azure PowerShell from here: http://go.microsoft.com/?linkid=9811175&clcid=0x409
38+
2. Provide the appropriate values for each variable. Note: The angled brackets should not be included in the values you provide.
39+
40+
41+
#>
42+
43+
#Provide the subscription Id
44+
$subscriptionId = 'yourSubscriptionId'
45+
46+
#Provide the name of your resource group
47+
$resourceGroupName ='yourResourceGroupName'
48+
49+
#Provide the name of the Managed Disk
50+
$diskName = 'yourDiskName'
51+
52+
#Provide the size of the disks in GB. It should be greater than the VHD file size.
53+
$diskSize = '128'
54+
55+
#Provide the URI of the VHD file that will be used to create Managed Disk.
56+
# VHD file can be deleted as soon as Managed Disk is created.
57+
# e.g. https://contosostorageaccount1.blob.core.windows.net/vhds/contoso-um-vm120170302230408.vhd
58+
$vhdUri = 'https://contosoststorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd'
59+
60+
#Provide the resource Id of the storage account where VHD file is stored.
61+
#e.g. /subscriptions/6472s1g8-h217-446b-b509-314e17e1efb0/resourceGroups/MDDemo/providers/Microsoft.Storage/storageAccounts/contosostorageaccount
62+
$storageAccountId = '/subscriptions/yourSubscriptionId/resourceGroups/yourResourceGroupName/providers/Microsoft.Storage/storageAccounts/yourStorageAccountName'
63+
64+
#Provide the storage type for the Managed Disk. PremiumLRS or StandardLRS.
65+
$sku = 'Premium_LRS'
66+
67+
#Provide the Azure location (e.g. westus) where Managed Disk will be located.
68+
#The location should be same as the location of the storage account where VHD file is stored.
69+
#Get all the Azure location using command below:
70+
#Get-AzureRmLocation
71+
$location = 'westus'
72+
73+
#Set the context to the subscription Id where Managed Disk will be created
74+
Set-AzContext -Subscription $subscriptionId
75+
76+
#If you're creating an OS disk, add the following lines
77+
#Acceptable values are either Windows or Linux
78+
#$OSType = 'yourOSType'
79+
#Acceptable values are either V1 or V2
80+
#$HyperVGeneration = 'yourHyperVGen'
2581
26-
[!code-powershell[main](../../../new_powershell_scripts/managed-disks/create-managed-disks-from-vhd-in-different-subscription.ps1 "Create managed disk from VHD")]
82+
#If you're creating an OS disk, add -HyperVGeneration and -OSType parameters
83+
$diskConfig = New-AzDiskConfig -SkuName $sku -Location $location -DiskSizeGB $diskSize -SourceUri $vhdUri -CreateOption Import
2784
85+
#Create Managed disk
86+
New-AzDisk -DiskName $diskName -Disk $diskConfig -ResourceGroupName $resourceGroupName -StorageAccountId $storageAccountId
87+
```
2888

2989
## Script explanation
3090

0 commit comments

Comments
 (0)