Which team is your organization’s GIF champion?


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:

$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++}
Displayname = $team.displayname
Count = $TeamGIF
$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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s