Created
August 3, 2019 20:59
-
-
Save AlexanderHolmeset-zz/f80ab699fbc9590ed81426c50589af3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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