Which team is your organization’s GIF champion?

1200px-Microsoft_Office_Teams_(2018–present).svg

Just a short silly weekend scripting project to get started after the summer vacation.
This script counts how many GIF’s are used in each Microsoft Teams team, and give you the stats from top to bottom.

Take a look here if you don’t know how to get an access token for Graph API requests in PowerShell. Also, remember if your graph requests return more than a hundred objects, you will need to do another request for the next hundred. Will updated code and write another blogpost on how to handle large number of objects in your requests.

Lee Ford beat me to it, so take a look at his post to handle large returns in requests:
https://www.lee-ford.co.uk/graph-api-paging/

$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

Link to script if embedded version fails

 

One thought on “Which team is your organization’s GIF champion?

Leave a comment