Azure CLI で Windows11 のVMを起動/削除/イメージ作成/イメージからの起動をする
Azure CLI で Windows11 のVMを起動/削除/イメージ作成/イメージからの起動をする手順を解説します。
サブスクリプションの指定(省略可)
az account set --subscription "******-******-******-******"
***-***-***-***-***
にはサブスクリプションIDを指定します。
リソースグループの作成
az group create^
--name vm_resource_group^
--location japaneast
Windows VM の起動
az vm create --location japaneast^
--resource-group vm_resource_group^
--name win-11-vm^
--image MicrosoftWindowsDesktop:Windows-11:win11-22h2-pro:latest^
--size Standard_B1ms^
--public-ip-address public_ip_01^
--public-ip-sku Standard^
--data-disk-delete-option Delete^
--os-disk-delete-option Delete^
--nic-delete-option Delete^
--nsg nsg_01^
--vnet-name vnet_01^
--priority Regular^
--nsg-rule RDP^
--admin-username admin01^
--admin-password SampleVM!123
👇下記内容が出力されるので、publicIpAddressを利用してリモートデスクトップ接続できます。
{
"fqdns": "",
"id": "/subscriptions/*****-*****-*****/resourceGroups/vm_resource_group/providers/Microsoft.Compute/virtualMachines/win-11-vm",
"location": "japaneast",
"macAddress": "**********",
"powerState": "VM running",
"privateIpAddress": "10.0.0.4",
"publicIpAddress": "**.**.**.**",
"resourceGroup": "vm_resource_group",
"zones": ""
}
👇リモートデスクトップ接続イメージ


VM停止
az vm deallocate^
--resource-group vm_resource_group^
--name win-11-vm
VMイメージ作成
az sig create^
--resource-group vm_resource_group^
--location japaneast^
--gallery-name shared_image_gallery_01
az sig image-definition create^
--resource-group vm_resource_group^
--gallery-name shared_image_gallery_01^
--gallery-image-definition win-11-vm-image_01^
--publisher GreatPublisher^
--offer Windows-11^
--sku win11-22h2-pro^
--os-type windows^
--hyper-v-generation V2^
--location japaneast^
--features SecurityType=TrustedLaunch^
--os-state Specialized
az sig image-version create^
--resource-group vm_resource_group^
--gallery-name shared_image_gallery_01^
--gallery-image-definition win-11-vm-image_01^
--gallery-image-version 0.0.1^
--location japaneast^
--virtual-machine /subscriptions/***-***-***-***-***/resourceGroups/vm_resource_group/providers/Microsoft.Compute/virtualMachines/win-11-vm^
--no-wait
***-***-***-***-***
にはサブスクリプションIDを指定します。
イメージからのVM作成
az vm create --location japaneast^
--resource-group vm_resource_group^
--name win-11-vm^
--image /subscriptions/***-***-***-***-***/resourceGroups/vm_resource_group/providers/Microsoft.Compute/galleries/shared_image_gallery_01/images/win-11-vm-image_01^
--size Standard_B1ms^
--public-ip-address public_ip_01^
--public-ip-sku Standard^
--data-disk-delete-option Delete^
--os-disk-delete-option Delete^
--nic-delete-option Delete^
--nsg nsg_01^
--vnet-name vnet_01^
--priority Regular^
--nsg-rule RDP^
--specialized true^
--security-type TrustedLaunch^
--admin-username admin01^
--admin-password SampleVM!123
***-***-***-***-***
にはサブスクリプションIDを指定します。
VM削除
az vm delete^
--resource-group vm_resource_group^
--name win-11-vm^
--yes
リソースグループの削除
az group delete^
--name vm_resource_group^
--yes