Accepting Azure Marketplace terms in PowerShell
Marketplace terms…
If you’ve ever deployed resources into Azure from the Marketplace at the point of deployment you’ll often see the screen shown below:
You’re accepting the terms of use for the Marketplace offering for the subscription you’re currently working within.
However if you try to deploy a resource from the Marketplace through a json template and you’ve not accepted the terms previously you’ll get an error like so:
The error message is fairly self explanatory, Code=MarketplacePurchaseEligibilityFailed
indicates you’re not eligible to deploy the resource and Legal terms have not been accepted for this item on this subscription
make it clear what the issue is.
There are a couple of ways you can accept the legal terms, you could deploy through the Azure Portal (which if you’re planning to deploy through a json template you probably don’t want to do). You can use the REST API to programmatically review and accept the terms as discussed by Arsen Vladmirskiy here or you can use PowerShell which I’ll explain further below.
Accepting Marketplace terms with PowerShell
There are 2 PowerShell cmdlets that you’ll need to use
Get-AzureRmMarketplaceTerms and Set-AzureRmMarketplaceTerms.
Get-AzureRmMarketplaceTerms will get the agreement terms for a given publisher id(Publisher), offer id(Product) and plan id(Name). The example below will return the terms for a Data Science Virtual Machines available in the Marketplace
Get-AzureRmMarketplaceTerms -Publisher "microsoft-ads" -Product "windows-data-science-vm" -Name "windows2016"
Note in the screenshot above Accepted has a value of False.
To accept these terms we just need to pipe Get-AzureRmMarketplaceTerms into the Set-AzureRmMarketplaceTerms with the -Accept switch.
Get-AzureRmMarketplaceTerms -Publisher "microsoft-ads" -Product "windows-data-science-vm" -Name "windows2016" | Set-AzureRmMarketplaceTerms -Accept
As you can see Accepted now shows a value of true and you’ll be able to complete deployment of your resource from the Marketplace using your json template.
I think the AzureRM.MarketplaceOrdering namespace which the Get-AzureRmMarketplaceTerms and Set-AzureRmMarketplaceTerms cmdlets exist within was introduced in AzureRM PowerShell Module 4.4.1, so if you’re using an earlier version of the module you’ll need to update to make these cmdlets available for use.