我正在尝试使用下面的脚本导出所有团队频道及其会员类型。但是,它出错了。
{}
$response = Invoke-RestMethod -Method Post -Uri $url -Body $body
$accessToken = $response.access_token
# Set the authorization header
$headers = @{
Authorization = "Bearer $accessToken"
}
# Get all teams in the tenant
$url = "https://graph.microsoft.com/v1.0/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')"
$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
$teams = $response.value
# Create a list to store the output data
$outputData = @()
# Iterate over each team
foreach ($team in $teams) {
$teamId = $team.id
$teamName = $team.displayName
# Get the channels for the current team
$url = "https://graph.microsoft.com/v1.0/teams/$teamId/channels"
$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
$channels = $response.value
# Iterate over each channel
foreach ($channel in $channels) {
$channelId = $channel.id
$channelName = $channel.displayName
# Create a custom object to store the data for the current channel
$obj = New-Object PSObject
Add-Member -InputObject $obj -MemberType NoteProperty -Name "Team Name" -Value $teamName
Add-Member -InputObject $obj -MemberType NoteProperty -Name "Channel Name" -Value $channelName
Add-Member -InputObject $obj -MemberType NoteProperty -Name "Membership Type" -Value $channel.membershipType
# Add the custom object to the output data list
$outputData += $obj
}
}
# Export the output data to a CSV file
$outputData | Export-Csv -Path $outputFile -NoTypeInformation
Write-Host "Done! The membership type of all channels has been exported to '$outputFile'."
}
错误:
Invoke-RestMethod :远程服务器返回错误:(404) 不 成立。行:40 字符:17
我知道它失败了
$url = "https://graph.microsoft.com/v1.0/teams/$teamId/channels"
$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
尝试使用 graphexpolrer 来验证是否可以做到这一点。该 url 提供频道详细信息和会员类型。但是,当尝试使用不同的组合编写脚本时,它会失败。即使通过 CSV 文件提供,也无法进一步提取频道信息。任何指示将不胜感激。
参考使用 - https://learn.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-1.0&tabs=http