Skip to content

Instantly share code, notes, and snippets.

@JayDoubleu
Created April 7, 2020 01:06
Show Gist options
  • Save JayDoubleu/d572999524e6af95c0f7530a2bdbd6fb to your computer and use it in GitHub Desktop.
Save JayDoubleu/d572999524e6af95c0f7530a2bdbd6fb to your computer and use it in GitHub Desktop.
azure partner information powershell billing
function Get-AccessToken {
$context = Get-AzContext
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($profile)
$token = $profileClient.AcquireAccessToken($context.Subscription.TenantId)
return $token.AccessToken
}
function Get-AzSubscriptionPartner {
param(
[Parameter(Mandatory = $true)]
[string]$subscription
)
$access_token = Get-AccessToken
$headers = @{"Authorization" = "Bearer $access_token"; "Accept" = "application/json" };
$url = "https://bmxservice.trafficmanager.net/api/Billing/Subscription/GetPartnerInformation?api-version=2019-01-14&subscriptionGuid=$subscription"
$response = (Invoke-WebRequest -Method GET -Uri $url -ContentType "application/json" -Headers $headers).Content|ConvertFrom-Json
Select-Object @{n='Subscription';e={$subscription}},@{n='PartnerId';e={$response.partnerId}},@{n='PartnerName';e={$response.partnerName}} -InputObject ''
}
function Set-AzSubscriptionPartner {
param(
[Parameter(Mandatory = $true)]
[string]$subscription,
[Parameter(Mandatory = $true)]
[string]$partnerid
)
$access_token = Get-AccessToken
$headers = @{"Authorization" = "Bearer $access_token"; "Accept" = "application/json" };
$url = "https://bmxservice.trafficmanager.net/api/Billing/Subscription/SetPartnerInformation?api-version=2019-01-14"
$data = @{
subscriptionGuid = $subscription
partnerId = $partnerid
}
$json = $data | ConvertTo-Json
$response = (Invoke-WebRequest -Method POST -Uri $url -ContentType "application/json" -Headers $headers -body $json).StatusCode
Select-Object @{n='Subscription';e={$subscription}},@{n='StatusCode';e={$response}} -InputObject ''
}
@bacsiden
Copy link

This code doesn't work, the token built from $context does not have permission to set Partner Id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment