Back to script library
Entra / Microsoft 365 · Teams

Get Teams reactions

Report emoji reactions found in Teams channel messages over a date range.

Connect & set up

Run these once per session. All scopes are read-only unless the script makes changes.

Connect-MgGraph -Scopes Channel.ReadBasic.All -NoWelcome

Run it

The main script. Copy it, or download the .ps1 and run it from your console.

param(
[int] $LookbackDays = 90,
[string] $StartDate = (Get-Date).AddDays(-$LookbackDays),
[string] $EndDate = (Get-Date).AddDays(1)
)
$Modules = @( "ExchangeOnlineManagement" )
# Requires -Modules $Modules
$ModulesLoaded = Get-Module | Select Name
If (!($ModulesLoaded -match "ExchangeOnlineManagement")) {Write-Host "Please connect to the Exchange Online management module and then restart the script"; break}
Connect-MgGraph -Scope Channel.ReadBasic.All
Write-Host "Finding audit records for teams reactions..."
[array]$Records = Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -Formatted -ResultSize 5000 -Operations ReactedToMessage
If (!($Records)) {Write-Host "Error: Can't find any audit records to process - exiting" ; break}
Write-Host ("Processing {0} audit records..." -f $Records.count)
$Report = [System.Collections.Generic.List[Object]]::new()
$i = 0
ForEach ($Rec in $Records) {
$i++
Write-Host ("Processing record {0} of {1}" -f $i, $Records.count)
$AuditData = $Rec.AuditData | ConvertFrom-Json
If ($AuditData.ChannelName) { # Reaction to channel message
$Type = "Channel"
$Team = Get-MgTeam -TeamId $AuditData.AADGroupId | Select-Object -ExpandProperty DisplayName
$Channel = Get-MgTeamChannel -TeamId $AuditData.AADGroupId | Where-Object {$_.id -eq $AuditData.ChannelGuid} | Select-Object -ExpandProperty DisplayName
$MessageThread = $AuditData.TeamGuid
$MessageId = $AuditData.MessageId
}
Else {
$Team = $Null; $Channel = $Null
$Type = "Chat"
$Channel = $AuditData.CommunicationType
$MessageThread = $AuditData.ChatThreadId
$MessageId = $AuditData.MessageId
} # End If
# Check for reactions removed
If (!($AuditData.MessageReactionType)) {
$AuditText = $Auditdata.Extraproperties | Where-Object {$_.Key -eq "Source"} | Select-Object -ExpandProperty Value
$Reaction = ("{0} ({1})" -f $AuditText, $AuditData.OldValue)
} Else {
$Reaction = $AuditData.MessageReactionType }
$ReportLine = [PSCustomObject][Ordered]@{
Date = $Rec.CreationDate
User = $Rec.UserIds
Reaction = $Reaction
Type = $Type
Team = $Team
Channel = $Channel
Thread = $MessageThread
Message = $MessageId
}
$Report.Add($ReportLine)
} # End ForEach Records
$Report | Group-Object Reaction | Sort-Object Count -Descending | Format-Table Name, Count
$Report | Out-GridView

Parameters

ParameterDefaultNotes
-LookbackDays90Number of days of channel messages to scan for reactions.
-StartDate(Get-Date).AddDays(-90)Start of the reporting window.
-EndDate(Get-Date).AddDays(1)End of the reporting window.
Attribution