How to include “Plan information” when creating ARM VM from a captured image using Powershell?

半城伤御伤魂 提交于 2019-11-29 11:18:56

As of five days ago, and Azure Powershell version 1.2.2 they added a new cmdlet to the AzureRM.Compute - Set-AzureRmVMPlan

This let's you configure the plan parameter like this -

$vm = New-AzureRmVMConfig -vmName $vmName -vmSize $vmSize

Set-AzureRmVMPlan -VM $vm -Publisher bitnami -Product lampstack -Name "5-6"
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $vhdName -VhdUri $vhdUri -Linux -CreateOption attach -Verbose
techcrunchone

The following command in azure cli provides the information. Example run below.

azure vm image show --location westus --publisher paloaltonetworks --offer vmseries1 --sku bundle1 --version 7\.1\.1 --json

[
  {
    "id": "/Subscriptions/subscription-id/Providers/Microsoft.Compute/Locations/westus/Publishers/paloaltonetworks/ArtifactTypes/VMImage/Offers/vmseries1/Skus/bundle1/Versions/7.1.1",
    "name": "7.1.1",
    "location": "westus",
    "plan": {
      "publisher": "paloaltonetworks",
      "name": "bundle1",
      "product": "vmseries1"
    },
    "osDiskImage": {
      "operatingSystem": "Linux"
    },
    "dataDiskImages": []
  }
]

set-azurermvmplan command fixed the error. We should get all the parameters from automation script section of portal.

For anyone else that ends up here like I did, if you don't know the publisher or anything.

Save variables for new vm name $VM_NAME, resource group $RESOURCE_GROUP, and location $REGION, then run the following commands and create associated variables:

VM_NAME=<new-vm-name>
RESOURCE_GROUP=<my-resource-group>
REGION=<my-disks-location>

Get $PLAN_NAME, $PLAN_PRODUCT, $PLAN_PUBLISHER **this command can take forever. you can shorten the wait if you can provide '--publisher', '--offer' or '--sku'.*

az vm image list --location $REGION --all -o table | grep <any-keyword>

PLAN_NAME=<output-from-command-above>
PLAN_PRODUCT=<output-from-command-above>
PLAN_PUBLISHER=<output-from-command-above>

Get available disks and save to variables $OS_DISK and $OS_TYPE

az disk list -o table

OS_DISK=<output-from-command-above>
OS_TYPE=<output-from-command-above>

Get list of nics (if available) and save to variables $NIC

az network nic list -o table

NIC=<output-from-command-above>

Get available vm sizes and save to variables $VM_SIZE

az vm list-sizes -l $REGION -o table

VM_SIZE=<output-from-command-above>

Once all the variables are set you can run this command to recreate the machine:

az vm create \
  --name $VM_NAME \
  --resource-group $RESOURCE_GROUP \
  --attach-os-disk $OS_DISK \
  --os-type $OS_TYPE \
  --location $REGION \
  --size $VM_SIZE \
  --plan-name $PLAN_NAME \
  --plan-product $PLAN_PRODUCT \
  --plan-publisher $PLAN_PUBLISHER \
  --nics $NIC
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!