Created
April 7, 2020 01:06
-
-
Save JayDoubleu/d572999524e6af95c0f7530a2bdbd6fb to your computer and use it in GitHub Desktop.
azure partner information powershell billing
This file contains 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
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 '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code doesn't work, the token built from $context does not have permission to set Partner Id