Microsoft Teams 频道会员导出

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

我正在尝试使用下面的脚本导出所有团队频道及其会员类型。但是,它出错了。

{}
$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

microsoft-teams microsoft-graph-teams
1个回答
0
投票

与其直接从 PowerShell 调用 Graph ,我强烈建议使用专门为此构建的 PowerShell 库 - 它更容易用于连接和发送和接收类型化对象,而不是原始 json(它包装了所有这些)为你)。

查看更多信息

https://learn.microsoft.com/en-us/powershell/microsoftgraph/get-started?view=graph-powershell-1.0

© www.soinside.com 2019 - 2024. All rights reserved.