编写Azure Time Series Insights数据访问策略脚本
使用编写Azure Time Series Insights数据访问策略脚本,azure,powershell,azure-sdk,azure-rest-api,azure-timeseries-insights,Azure,Powershell,Azure Sdk,Azure Rest Api,Azure Timeseries Insights,使用数据访问策略可以手动将用户添加到时间序列洞察。 尽管如此,仍无法批量添加用户 是否可以使用PowerShell/Azure REST API/SDK对这两个场景进行脚本化/自动化?根据我的研究,我们可以使用以下Azure REST API在时间序列洞察策略中创建数据访问策略。有关更多详细信息,请参阅 比如说 Connect-AzAccount $tenantId="<your tenant id>" $resource="https://management.core.
数据访问策略
可以手动将用户添加到时间序列洞察
。
尽管如此,仍无法批量添加用户
是否可以使用PowerShell/Azure REST API/SDK对这两个场景进行脚本化/自动化?根据我的研究,我们可以使用以下Azure REST API在时间序列洞察策略中创建数据访问策略。有关更多详细信息,请参阅 比如说
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
连接AzaAccount
$tenantId=“”
$resource=”https://management.core.windows.net/"
$context=获取上下文
$token=$context.TokenCache.ReadItems()|其中对象{($\.TenantId-eq$TenantId)-和($\.Resource-eq$Resource)}
$accesstoken=$token.accesstoken
$body=@{
“财产”=@{
“principalObjectId=”“
“角色”=@(“读者”)
“说明”=“读卡器”
}
}|转换为Json
$url=”https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/accessPolicies/{accessPolicyName}?api版本=2018-08-15-preview“
$result=Invoke RestMethod-Uri$url-Method Put-Headers@{“Authorization”=“Bearer$accesstoken”}-Body$Body-UseBasicParsing
$result.properties
嗨,我能知道你的问题是否解决了吗?如果我在下面提供的解决方案有效,请您将我的回答标记为“已接受”,谢谢。
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