I have Azure Log Analytics and Azure Application Insights. I want to set certain tables in my Log Analytics to "Basic Logs" because that is cheaper. First I want to just check the settings for these tables.
I am trying to follow this article: https://docs.microsoft.com/en-us/azure/azure-monitor/logs/basic-logs-configure?tabs=api-2
The article tells me to get a bearer token by following this other article: https://social.technet.microsoft.com/wiki/contents/articles/51140.azure-rest-management-api-the-quickest-way-to-get-your-bearer-token.aspx
I extract a bearer token from the Azure Portal using the developer tools. It looks like this (a few hundred characters long): Bearer ey...A.
I then try to do this in PowerShell:
$BearerToken = "Bearer ey...A"
$uri = "https://management.azure.com/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.OperationalInsights/workspaces/<workspaceName>/tables/<tableName>?api-version=2021-12-01-preview"
Invoke-WebRequest $uri -Headers @{Authorization = $BearerToken}
This gives me:
{"error":{"code":"InvalidAuthenticationToken","message":"The access token is invalid."}}
In my PowerShell session I am logged in as the same user as in the Portal (using az login).
Might it be a rights issue? I have "Owner" and "Contributor" access to the Log Analytics workspace.
What do I need to do to get through the authentication? Do I need any further headers or options on my Invoke-WebRequest call?