Use an Application Image from the Azure Marketplace using PowerShell

I recently needed to deploy a special type of VM from the Azure Marketplace using PowerShell and the deployment was not the same as regular Windows or Linux VM.

First I knew the app I wanted to use, e.g. https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft-ads.windows-data-science-vm but wasn’t sure of the publisher or offer. With hindsight it shows you right in the URL, Microsoft-ads is the publisher and windows-data-science-vm is the offer but I initially just searched for what I wanted using the following and looked for it (first part of the code), then got the detail as usual (last two lines):

$publishers = Get-AzureRmVMImagePublisher -Location $Region
foreach($publisher in $publishers)
{
    Get-AzureRmVMImageOffer -Location $Region -PublisherName $publisher.PublisherName | ft Offer,PublisherName -AutoSize
}
Get-AzureRmVMImageSku -Location $Region -PublisherName "microsoft-ads" -Offer "windows-data-science-vm"
Get-AzureRmVMImage -Location $Region -PublisherName "microsoft-ads" -Offer "windows-data-science-vm" -Skus "windows2016"

Now I knew the publisher, offer and SKU I could add that configuration to my VM.

$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName microsoft-ads -Offer windows-data-science-vm `
    -Skus windows2016 -Version latest

However, when using the application there are a few other steps. You need to set a plan and also accept the terms of the app. Fortunately it’s easy to do.

$vm = Set-AzureRmVMPlan -VM $vm -Name windows2016 -Product windows-data-science-vm -Publisher microsoft-ads

#Have to accept terms
Get-AzureRmMarketplaceTerms -Name windows2016 -Product windows-data-science-vm -Publisher microsoft-ads |
    Set-AzureRmMarketplaceTerms -Accept

That was it. Basically the only additional work is setting the plan and accepting the marketplace terms and the data needed for those commands are the same values used for the source image, just PublisherName > Publisher, Offer > Product and SKUs > Name. The exact same would apply if using JSON. Easy!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: