Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset-zz
Created August 3, 2019 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderHolmeset-zz/f80ab699fbc9590ed81426c50589af3b to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset-zz/f80ab699fbc9590ed81426c50589af3b to your computer and use it in GitHub Desktop.
$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