次の方法で共有


PowerShell を使用してスナップショットからマネージド ディスクを作成する

このスクリプトは、スナップショットからマネージド ディスクを作成します。 これを使用して、OS ディスクとデータ ディスクのスナップショットから仮想マシンを復元します。 OS およびデータのマネージド ディスクをそれぞれのスナップショットから作成してから、マネージド ディスクを接続することで新しい仮想マシンを作成します。 スナップショットから作成されたデータ ディスクを接続することで既存の VM のデータ ディスクを復元することもできます。

Azure サブスクリプションをお持ちでない場合は、開始する前に Azure 無料アカウントを作成してください。

サンプル スクリプト

#Provide the subscription Id
$subscriptionId = 'yourSubscriptionId'

#Provide the name of your resource group
$resourceGroupName ='yourResourceGroupName'

#Provide the name of the snapshot that will be used to create Managed Disks
$snapshotName = 'yourSnapshotName'

#Provide the name of the Managed Disk
$diskName = 'yourManagedDiskName'

#Provide the size of the disks in GB. It should be greater than the VHD file size.
$diskSize = '128'

#Provide the storage type for Managed Disk. Acceptable values are Standard_LRS, Premium_LRS, PremiumV2_LRS, StandardSSD_LRS, UltraSSD_LRS, Premium_ZRS and StandardSSD_ZRS.
$storageType = 'Premium_LRS'

#Required for Premium SSD v2 and Ultra Disks
#Provide the Availability Zone you'd like the disk to be created in, default is 1
$zone=1

#Provide the Azure region (e.g. westus) where Managed Disks will be located.
#This ___location should be same as the snapshot ___location
#Get all the Azure ___location using command below:
#Get-AzLocation
$___location = 'westus'

#Set the context to the subscription Id where Managed Disk will be created
Select-AzSubscription -SubscriptionId $SubscriptionId

$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName 

#If you're creating a Premium SSD v2 or an Ultra Disk, add "-Zone $zone" to the end of the command
$diskConfig = New-AzDiskConfig -SkuName $storageType -Location $___location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize
 
New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName

スクリプトの説明

このスクリプトでは、以下のコマンドを使ってスナップショットからマネージド ディスクを作成します。 表内の各コマンドは、それぞれのドキュメントにリンクされています。

コマンド 注記
Get-AzSnapshot を実行する スナップショットのプロパティを取得します。
New-AzDiskConfig ディスクの作成に使用されるディスク構成を作成します。 これには、親スナップショットのリソース ID、親スナップショットの場所と同じ場所、ストレージの種類が含まれます。
New-AzDisk パラメーターとして渡されるディスク構成、ディスク名、およびリソース グループ名を使用してディスクを作成します。

次のステップ

マネージド ディスクから仮想マシンを作成する

Azure PowerShell モジュールの詳細については、Azure PowerShell のドキュメントを参照してください。

その他の仮想マシンの PowerShell スクリプト サンプルについては、Azure Windows VM のドキュメントを参照してください。