使用 API 和 Powershell 创建 Azure Purview 集合

问题描述 投票:0回答:1

这是我第一次使用API。

我正在尝试使用 API 和 powershell 创建权限子集合。

$tenantID =“XXXXXXXXXXXXXXXXXXXXXXX”

$url =“https://login.microsoftonline.com/$tenantID/oauth2/token”

$params = @{ client_id = "XXXXXXXXXXXXXXXXXXXXXXX"; client_secret = "XXXXXXXXXXXXXXXXXXXXXXXX"; grant_type = "client_credentials";资源='https://purview.azure.net'}

$bearertoken = Invoke-WebRequest $url -Method Post -Body $params -UseBasicParsing | ConvertFrom-Json

$accesstoken = ConvertTo-SecureString $bearertoken.access_token -AsPlainText -Force

$purviewendpoint =“https://testpurview.purview.azure.com/account”

$url =“$purviewendpoint/collections/newcollection1?api-version=2019-11-01-preview”

$childcollection = @"
  {
    "parentCollection": {
      "referenceName": "**testpurview**"
    }
  }
"@

Invoke-RestMethod -Method PUT -Uri $url -Body $childcollection -Token $accesstoken

我尝试的步骤:

创建了一个不记名令牌。 从不记名令牌为 access_token 创建了一个变量。

newcollection1:我要创建的新子集合。

testpurview:这是我的 Purview 帐户的根集合。

如果这是创建集合的正确方法,有人可以帮助我吗?

azure-powershell azure-purview
1个回答
0
投票

您可以尝试以下方法。

$tenantId = "<tenant-id>"
$clientId = "<client-id>"
$clientSecret = "<client-secret>"
$accountName = "<purview-account-name>"
$parentCollectionId = "<parent-collection-id>"
$subcollectionName = "<subcollection-name>"

$context = Connect-AzAccount -TenantId $tenantId -ServicePrincipal -Credential (New-Object System.Management.Automation.PSCredential($clientId, (ConvertTo-SecureString $clientSecret -AsPlainText -Force)))

$token = $context.TokenCache.ReadItems() | Where-Object { $_.Resource -eq "https://purview.azure.net" } | Select-Object -First 1

$body = @{
    name = $subcollectionName
}

# Send the request to create the subcollection
$uri = "https://$accountName.purview.azure.com/collections/$parentCollectionId/subcollections?api-version=2021-07-01-preview"
Invoke-RestMethod -Method Post -Uri $uri -Headers @{ Authorization = "Bearer $($token.AccessToken)" } -Body ($body | ConvertTo-Json)
© www.soinside.com 2019 - 2024. All rights reserved.