title: How to include "Plan information" when creating ARM VM from a captured image using Powershell?
body: <p>I have a ARM VM created from a Marketplace: bitnami LAMP (Ubuntu)
  I've successfully captured an image. During the capture I've saved the json template. </p>
  
  <p>Using a template based on that I can successfully create new VMs via the portal's Template Deployment facility interactively. (so the captured image is OK). Please note: That json template <strong>do include</strong> plan information, see below</p>
  
  <p>However my original goal is to create new ARM VMs based on the captured image <strong>using Powershell</strong></p>
  
  <p>All seems to work however in the last command New-AzureRmVM returns and error stating:</p>
  
  <blockquote>
    <p>Creating a virtual machine from Marketplace image requires Plan
    information in the request.</p>
  </blockquote>
  
  <p><em>Obviously this information is missing, but I can not find out how to add it.</em></p>
  
  <p><strong>Here is what I've tried:</strong></p>
  
  <ul>
  <li>I've examined the $vm variable (what is the parameter of the New-AzureRmVM command) and its Plan property is empty. (as expected)</li>
  <li>I've searched for appropiate Add-AzureRmVm... commands with no success</li>
  <li>I've tried to set manually the Plan property and its subproperties in <strong><em>all caseing</em></strong> combinations: all thows error. (like $vm.Plan.Publisher="bitnami")</li>
  </ul>
  
  <p>Actually the original capture's json template contains that Plan intomation:</p>
  
  <pre><code>  },
    "name": "[parameters('vmName')]",
    "type": "Microsoft.Compute/virtualMachines",
    "location": "westeurope",
    "plan": {
      "name": "5-6",
      "publisher": "bitnami",
      "product": "lampstack"
    } 
  </code></pre>
  
  <p>Again, the captured image (the .vhd) what this script tries to use is confirmed OK, because with the very same captured image I can create new ARM VMs via the portal's Template Deployment facility.</p>
  
  <hr>
  
  <p>I think the source is not too important this case (there are no error in it, just missing things, but that missing thing is clearly stated in the question) 
  but I attach the source anyway... <strong>Optional reading</strong>.</p>
  
  <pre><code># Existing resource parameters
  $subscriptionName =  'Visual Studio Premium with MSDN'
  $rgName = "rg-wp"
  $location = "westeurope"
  $stName = 'mystorage' 
  $sourceImageUri = 'https://mystorage.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd' 
  
  # Creation settings:
  $vmSize = 'Standard_DS2'
  $vmSuffix = 'wp-11'
  
  #Login-AzureRmAccount
  Select-AzureRmSubscription -SubscriptionName $subscriptionName
  
  # Get the storage account
  #$storageAccount = Get-AzureRmStorageAccount | ? StorageAccountName -EQ $stName
  $storageAccount = Get-AzureRmStorageAccount -AccountName $stName -ResourceGroupName $rgName 
  
  # Enable verbose output and stop on error
  $VerbosePreference = 'Continue'
  #$ErrorActionPreference = 'Stop'
  
  $adminUsername = 'myusername'
  $adminPassword = 'mypassword'
  
  $vmName = '{0}-vm' -f $vmSuffix
  $nicName = '{0}-nic' -f $vmSuffix
  $ipName = '{0}-pip' -f $vmSuffix
  $domName = '{0}-mzpx' -f $vmSuffix
  $vnetName = '{0}-vn' -f $vmSuffix
  $nsgName= '{0}-nsg' -f $vmSuffix
  
  
  # Networking:
  Write-Verbose 'Creating Virtual Network'  
  $vnetDef = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Location $location -Name $vnetName -AddressPrefix '10.0.0.0/16'
  Write-Verbose 'Adding subnet to Virtual Network'  
  $vnet = $vnetDef | Add-AzureRmVirtualNetworkSubnetConfig -Name 'Subnet-1' -AddressPrefix '10.0.0.0/24' | Set-AzureRmVirtualNetwork
  
  Write-Verbose 'Creating Public IP'  
  $pip = New-AzureRmPublicIpAddress -ResourceGroupName $rgName -Location $location -Name $ipName -DomainNameLabel $domName -AllocationMethod Dynamic
  Write-Verbose 'Creating NIC'  
  $nsg = New-AzureRmNetworkSecurityGroup -Name $nsgName -ResourceGroupName $rgName -Location $location
  Write-Verbose 'Network Security Group'  
  $nic = New-AzureRmNetworkInterface -ResourceGroupName $rgName -Location $location -Name $nicName -PublicIpAddressId $pip.Id -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id
  
  # Configuring VM
  Write-Verbose 'Creating VM Config'  
  $vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize 
  
  # Specify local administrator account, and then add the NIC
  $cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force) # you could use Get-Credential instead to get prompted
  $vm = Set-AzureRmVMOperatingSystem -VM $vm -Linux -ComputerName $vmName -Credential $cred 
  $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
  
  # Specify the OS disk
  $diskName = '{0}-osdisk' -f $vmSuffix
  $osDiskUri = '{0}vhds/{1}{2}.vhd' -f $storageAccount.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $diskName
  $vm = Set-AzureRmVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $sourceImageUri -Linux
  
  Write-Verbose 'Creating VM...'  
  
  $result = New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
  </code></pre>