Created
April 22, 2021 18:23
-
-
Save azMantas/b5ae6a09730b5a0c1973aa097af03de5 to your computer and use it in GitHub Desktop.
Use personal access token to Invoke-RestMethod
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
$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$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