บทช่วยสอนนี้สาธิตวิธีการใช้เครื่องมือการเขียนโปรแกรมเพื่อสร้างรายงานการแยกข้ามผู้เช่า
ในบทช่วยสอนนี้ เรียนรู้วิธีการ:
- สร้างรายงาน
- รายการรายงานทั้งหมดสำหรับผู้เช่า
- ดึงรายงานเดียว
สร้างรายงาน
ใช้ข้อมูลต่อไปนี้เพื่อค้นหาวิธีต่าง ๆ ที่คุณสามารถสร้างรายงานใหม่ได้
หมายเหตุ
คุณสามารถสร้างได้หนึ่งรายงานต่อผู้เช่าต่อวันปฏิทินเท่านั้น
เพิ่มการดําเนินการใหม่ไปยังพื้นที่ทํางาน ค้นหา "สร้างคําขอเพื่อสร้างรายงานการเชื่อมต่อข้ามผู้เช่าสําหรับผู้เช่า หรือส่งกลับรายงานที่มีอยู่" ไม่จําเป็นต้องมีพารามิเตอร์
ใช้สคริป PowerShell ต่อไปนี้เพื่อสร้างรายงาน
Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '<client id of your Microsoft Entra ID application registration>' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}
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: สร้างรายงานการเชื่อมต่อข้ามผู้เช่า
รายการรายงานทั้งหมดสำหรับผู้เช่า
เพิ่มการดําเนินการใหม่ลงในพื้นที่ทํางาน โดยค้นหา "รายงานการเชื่อมต่อข้ามผู้เช่าสําหรับผู้เช่า" ไม่จําเป็นต้องมีพารามิเตอร์
ใช้สคริป PowerShell ต่อไปนี้เพื่อแสดงรายงานที่พร้อมใช้งานทั้งหมดสำหรับผู้เช่าของคุณ
Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '<client id of your Microsoft Entra ID application registration>' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}
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: รับรายงานการเชื่อมต่อข้ามผู้เช่า
ดึงรายงานเดียว
เพิ่มการดําเนินการใหม่ลงในพื้นที่ทํางาน โดยค้นหา "รับรายงานการเชื่อมต่อข้ามผู้เช่าตาม ID รายงานสําหรับผู้เช่า" ระบุ ID รายงานจากขั้นตอนก่อนหน้านี้
ใช้สคริป PowerShell ต่อไปนี้เพื่อดึงรายงานเดียวสำหรับผู้เช่าของคุณเกี่ยวกับการเชื่อมต่อที่ใช้ภายในผู้เช่า
Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '<client id of your Microsoft Entra ID application registration>' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}
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 - รายงานการเชื่อมต่อข้ามผู้เช่า