Skip to content

Instantly share code, notes, and snippets.

@azMantas
Created April 22, 2021 18:23
Show Gist options
  • Save azMantas/b5ae6a09730b5a0c1973aa097af03de5 to your computer and use it in GitHub Desktop.
Save azMantas/b5ae6a09730b5a0c1973aa097af03de5 to your computer and use it in GitHub Desktop.
Use personal access token to Invoke-RestMethod
$token = Get-AzAccessToken -Resource 'https://management.azure.com/'
$accesstoken = ConvertTo-SecureString -String $token.Token -AsPlainText -Force
$url = "https://management.azure.com/subscriptions?api-version=2020-01-01"
$GetSubscriptions = Invoke-RestMethod -Method get -Authentication OAuth -Token $accesstoken -ContentType 'application/json' -Uri $url
$GetSubscriptions.value | select id, displayName
@azMantas
Copy link
Author

azMantas commented Aug 2, 2021

$SubscriptionId = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
$token = Get-AzAccessToken -Resource 'https://management.azure.com/'
$accesstoken = ConvertTo-SecureString -String $token.Token -AsPlainText -Force
$url = "https://management.azure.com/subscriptions/$SubscriptionId/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018-07-01-preview"
Invoke-RestMethod -Method Post -Authentication OAuth -Token $accesstoken -ContentType 'application/json' -Uri $url

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