Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$GIFStats = @()
$apiUrl = "https://graph.microsoft.com/v1.0/groups"
$myProfile = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Get
$teams = $myProfile.value
foreach($team in $teams){
if($team.resourceProvisioningOptions -eq 'Team'){
$TeamGIF = 0
#Group/team object ID.
$TeamID = $team.ID
#Gets all channels in a Team
$apiUrl = "https://graph.microsoft.com/beta/teams/$TeamID/channels"
$myProfile = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Get
$TeamChannels = $myprofile.value | Select-Object ID
foreach($Channel in $TeamChannels) {
#Gets all root messages/conversations in a channel.
$apiUrl = "https://graph.microsoft.com/beta/teams/$TeamID/channels/"+$channel.id+"/messages"
$myProfile = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Get
$ChannelMessages = $myprofile.value
foreach($channelmessage in $ChannelMessages){
If((($channelmessage).body).Content -like '*.gif*'){$teamGIF++}
$apiUrl = "https://graph.microsoft.com/beta/teams/$TeamID/channels/"+$channel.id+"/messages/"+$ChannelMessage.id+"/replies"
$myProfile = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Get
$replies = $myprofile.value
foreach($reply in $replies){
If((($reply).body).Content -like '*.gif*'){$teamGIF++}
}
}
}
$Object=[PSCustomObject]@{
Displayname = $team.displayname
Count = $TeamGIF
}#EndPSCustomObject
$GIFStats+=$object
}
}
$GIFStats | Sort-Object count -Descending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.