编写Azure时间序列见解脚本数据访问策略 [英] Scripting Azure Time Series Insights Data Access Policies

查看:45
本文介绍了编写Azure时间序列见解脚本数据访问策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在一种使用数据访问策略将用户添加到 Time Series Insights 的手动方法.
尽管如此,无法批量添加用户.

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.

是否可以使用 PowerShell/Azure REST API/SDK 对这两种方案进行脚本化/自动化?

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

推荐答案

根据我的研究,我们可以使用以下Azure Rest API在时序分析"策略中创建数据访问策略.有关更多详细信息,请参阅文档

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

例如

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

这篇关于编写Azure时间序列见解脚本数据访问策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆