0

There exists a manual way to add users to the Time Series Insights using Data Access Policies.
Withstanding that, there is no way available to add users in bulk.

enter image description here

Can both the scenarios be scripted/automated using PowerShell/Azure REST API/SDK?

CodeWalker
  • 2,281
  • 4
  • 23
  • 50
  • Hi, may I know if your problem was solved ? If the solution I provided below works, could you please mark my answer as "accepted", thanks. – Hury Shen Mar 19 '20 at 02:42

1 Answers1

0

According to my research, we can use the following Azure Rest API to create data access policy in Time Series Insights policy. For more details, please refer to the document

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/accessPolicies/{accessPolicyName}?api-version=2018-08-15-preview

For example

Connect-AzAccount



$tenantId="<your tenant id>"
$resource="https://management.core.windows.net/"



$context=Get-AzContext 



$token=$context.TokenCache.ReadItems() |Where-Object { ($_.TenantId -eq $tenantId) -and ($_.Resource -eq $resource)  }
$accesstoken=$token.AccessToken
$body =@{
 "properties" = @{

  "principalObjectId" ="<the object id of the user or service principal>"
  "roles"= @("Reader")
  "description"="reader" 
 }



}| ConvertTo-Json



$url="https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/accessPolicies/{accessPolicyName}?api-version=2018-08-15-preview"
$result =Invoke-RestMethod -Uri $url  -Method Put -Headers @{"Authorization" = "Bearer $accesstoken"} -Body $body -UseBasicParsing



$result.properties

enter image description here

Hury Shen
  • 14,948
  • 1
  • 9
  • 18