Created
June 10, 2025 21:17
-
-
Save JustinGrote/2a1d5173f156e4af3c9e51b55a18a634 to your computer and use it in GitHub Desktop.
Scrape the Microsoft Partner Benefits AI for all redeemable Product Keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You will have to screen-scrape your bearer token and account GUID from the DevTools | |
$script:BaseUri = 'https://api.partnerbenefits.microsoft.com' | |
function Connect-PartnerBenefit { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[securestring]$ApiKey, | |
#Will connect to partner global account by default, specify this to choose a different account | |
[string]$AccountId | |
) | |
# Store the API key in a global variable for use in other functions | |
$SCRIPT:PSDefaultParameterValues['*-MSPartnerBenefit*:ApiKey'] = $ApiKey | |
$SCRIPT:PSDefaultParameterValues['*-MSPartnerBenefit*:AccountId'] = $AccountId | |
} | |
filter Add-PSType([string]$TypeName) { | |
$PSItem.PSObject.TypeNames.Insert(0, $TypeName) | |
$PSItem | |
} | |
function Get-MSPartnerBenefitCloudActiveProductEntitlement { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[string]$AccountId, | |
[Parameter(Mandatory)] | |
[securestring]$ApiKey | |
) | |
$url = "$BaseUri/v2/accounts/$AccountId/benefitsType/Cloud/activeproductentitlements" | |
Invoke-RestMethod -Uri $url -Authentication Bearer -Token $ApiKey | |
| Select-Object -Expand productEntitlements | |
| Add-PSType 'CloudProductEntitlement' | |
} | |
filter Get-MSPartnerBenefitKey { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[PSTypeName('CloudProductEntitlement')] | |
$ProductEntitlement, | |
#Your account GUID | |
[Parameter(Mandatory)] | |
[string]$AccountId, | |
[Parameter(Mandatory)] | |
[securestring]$ApiKey | |
) | |
$url = "$BaseUri/v1/accounts/$AccountId/subscribedsoftwareproducts/$($ProductEntitlement.id)/Keys" | |
Write-Verbose "Fetching $url" | |
Invoke-RestMethod -Uri $url -Authentication Bearer -Token $ApiKey ` | |
| Select-Object -Expand items | |
| Add-PSType 'CloudProductKey' | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment