次の方法で共有


チュートリアル: クロス テナント分離レポートの作成

このチュートリアルでは、Power Platform API を使用してテナント間の分離レポートを作成する方法を示します。

このチュートリアルで学習する内容は次のとおりです:

  1. Power Platform API を使用した認証
  2. レポートの作成
  3. テナントのすべてのレポートを一覧表示する
  4. 単一のレポートを取り込む

重要

テナント分離の詳細については、クロステナントの送受信の制限を参照してください。

ステップ 1. Power Platform API を使用して認証する

次の PowerShell スクリプトを使用して Power Platform API で認証する。

ヒント

Power Platform 管理者 Entra ID ロールを持つユーザーには、テナント分離の影響レポートを実行する権限があります。

Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '49676daf-ff23-4aac-adcc-55472d4e2ce0' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}

ステップ 2. レポートの作成

次の PowerShell スクリプトを使用してレポートを作成する。

メモ

テナントごと、暦日ごとに 1 つのレポートのみ作成できます。

try 
{
    # Create a cross tenant connections report
    $tenantReportCreateResponse = Invoke-RestMethod -Method Post -Uri "https://api.powerplatform.com/governance/crossTenantConnectionReports?api-version=2022-03-01-preview" -Headers $Headers -Body ""
    $reportId = $tenantReportCreateResponse.reportId
    $reportStatus = $tenantReportCreateResponse.status

    Write-Host "Cross tenant connections report created with ID=$reportId and status=$reportStatus" 

} catch {
    # Dig into the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Power Platform API 参照: クロステナント接続レポートの作成

ステップ 3. テナントのすべてのレポートを一覧表示する

次の PowerShell スクリプトを使用して、テナントで利用可能なすべてのレポートを一覧表示します。

try 
{
     # Get all available cross tenant connections reports for a tenant
    $tenantListReportResponse = Invoke-RestMethod -Method Get -Uri "https://api.powerplatform.com/governance/crossTenantConnectionReports?api-version=2022-03-01-preview" -Headers $Headers
    $report = $tenantListReportResponse | ConvertTo-Json -Depth 3 
    Write-Host $report 

} catch {
    # Dig into the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Power Platform API 参照: クロステナント接続レポートの取得

ステップ 4. 単一のレポートを取り込む

次の PowerShell スクリプトを使用して、テナント内で使用される接続に関するテナントの単一レポートを取得します。

try 
{
   # Get one cross tenant connections report for a tenant
    $tenantListReportResponse = Invoke-RestMethod -Method Get -Uri "https://api.powerplatform.com/governance/crossTenantConnectionReports/{$reportId}?api-version=2022-03-01-preview" -Headers $Headers
    $report = $tenantListReportResponse | ConvertTo-Json -Depth 2 
    Write-Host $report
    Write-Host "" 

} catch {
    # Go through the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Power Platform API 参照: クロス テナント接続レポートの一覧表示

関連項目

Power Platform API 参照 - クロス テナント接続レポートの一覧表示