Skip to content

Instantly share code, notes, and snippets.

@esell
Created January 19, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esell/7b70adb96b10998cd0d2e7b268400ec3 to your computer and use it in GitHub Desktop.
Save esell/7b70adb96b10998cd0d2e7b268400ec3 to your computer and use it in GitHub Desktop.
###########################################
# Generate or retrieve the API key - Log in to the Enterprise portal and follow the tutorial
# under Help - Reporting APIs. The first section under this help article explains how to
# generate or retrieve the API key for the specified enrollment.
# Source: https://docs.microsoft.com/en-us/azure/billing/billing-enterprise-api
#
# Endpoints and sample responses are here:
# https://docs.microsoft.com/en-us/rest/api/billing/enterprise/billing-enterprise-api-usage-detail#json-format
# You can use that documentation to help understand the key/values returned.
###########################################
$resource = "https://consumption.azure.com/v2/enrollments/YOUR_ENROLLMENT_NUMBER_HERE/usagedetails"
$result = Invoke-RestMethod -Method Get -Uri $resource -Header @{ "Authorization" = "bearer YOUR_API_KEY_HERE" }
Write-Output ("REST Call Result: '$($result)'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment