How to get a list of all the Programmatic Deployments

Issue:
How to get a list of all the Programmatic Deployments (Microsoft.MarketplaceOrdering/Agreements) from all the subscriptions in Tenant?

Currently not all resources types are available to be queried in Azure Resource Graph. Missing resource types require additional development work to enable in Azure Resource Graph.

Possible Solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Connect-AzAccount
Write-Host "Starting..."

$subscriptions = Get-AzSubscription
Write-Host $subscriptions.count

$report = @()
foreach ($sub in $subscriptions)
{
Write-Host $sub.Id
$uri = "https://management.azure.com/subscriptions/" + $sub.Id + "/providers/Microsoft.MarketplaceOrdering/agreements?api-version=2015-06-01"
Write-Host $uri

$Params = @{
"URI" = $uri
"Method" = 'GET'
"Headers" = @{
"Content-Type" = 'application/json'
"Accept" = 'application/json'
"Authorization" = 'Bearer yourBearerToken'
}
}

$res = Invoke-RestMethod @Params

If($res.value -ne ""){
foreach($agreement in $res.value){
$row =New-Object -TypeName PSObject -Property @{
SubscriptionName = $sub.Name
Publisher = $agreement.properties.publisher
Offer = $agreement.properties.offer
Sku = $agreement.name
State = $agreement.properties.state
}
$report += $row
}
}
}
$report | Export-Csv -Path c:\\tests\offers.csv -NoTypeInformation

Where to get the ApiKey:
1. Go to https://docs.microsoft.com/en-us/rest/api/marketplaceordering/marketplaceagreements/list
2. Click “Try it”
3. Copy the Api Key from “Request Preview”

HTH. 2021-3-2 By Jacky