Added Teams application process monitoring

pull/8/head
Danny de Vries 4 years ago
parent 16a9be2362
commit 624810fc27

@ -1,23 +1,23 @@
<# <#
.NOTES .NOTES
Name: Get-TeamsStatus.ps1 Name: Get-TeamsStatus.ps1
Author: Danny de Vries Author: Danny de Vries
Requires: PowerShell v2 or higher Requires: PowerShell v2 or higher
Version History: https://github.com/EBOOZ/TeamsStatus/commits/main Version History: https://github.com/EBOOZ/TeamsStatus/commits/main
.SYNOPSIS .SYNOPSIS
Sets the status of the Microsoft Teams client to Home Assistant. Sets the status of the Microsoft Teams client to Home Assistant.
.DESCRIPTION .DESCRIPTION
This script is monitoring the Teams client logfile for certain changes. It This script is monitoring the Teams client logfile for certain changes. It
makes use of two sensors that are created in Home Assistant up front. makes use of two sensors that are created in Home Assistant up front.
sensor.teams_status displays that availability status of your Teams client based sensor.teams_status displays that availability status of your Teams client based
on the icon overlay in the taskbar on Windows. sensor.teams_activity shows if you on the icon overlay in the taskbar on Windows. sensor.teams_activity shows if you
are in a call or not based on the App updates deamon, which is paused as soon as are in a call or not based on the App updates deamon, which is paused as soon as
you join a call. you join a call.
.PARAMETER SetStatus .PARAMETER SetStatus
Run the script with the SetStatus-parameter to set the status of Microsoft Teams Run the script with the SetStatus-parameter to set the status of Microsoft Teams
directly from the commandline. directly from the commandline.
.EXAMPLE .EXAMPLE
.\Get-TeamsStatus.ps1 -SetStatus "Offline" .\Get-TeamsStatus.ps1 -SetStatus "Offline"
#> #>
# Configuring parameter for interactive run # Configuring parameter for interactive run
Param($SetStatus) Param($SetStatus)
@ -45,14 +45,15 @@ If($null -ne $SetStatus){
break break
} }
# Clear the status variable at the start
$CurrentStatus = ""
# Start monitoring the Teams logfile when no parameter is used to run the script # Start monitoring the Teams logfile when no parameter is used to run the script
DO { DO {
# Get Teams Logfile and last icon overlay status # Get Teams Logfile and last icon overlay status
$TeamsStatus = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 100 | Select-String -Pattern ` $TeamsStatus = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 100 | Select-String -Pattern `
'Setting the taskbar overlay icon -',` 'Setting the taskbar overlay icon -',`
'StatusIndicatorStateService: Added',` 'StatusIndicatorStateService: Added' | Select-Object -Last 1
'Main window is closing',`
'main window closed' | Select-Object -Last 1
# Get Teams Logfile and last app update deamon status # Get Teams Logfile and last app update deamon status
$TeamsActivity = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 100 | Select-String -Pattern ` $TeamsActivity = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 100 | Select-String -Pattern `
'Resuming daemon App updates',` 'Resuming daemon App updates',`
@ -60,38 +61,44 @@ $TeamsActivity = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft
'SfB:TeamsNoCall',` 'SfB:TeamsNoCall',`
'SfB:TeamsPendingCall',` 'SfB:TeamsPendingCall',`
'SfB:TeamsActiveCall' | Select-Object -Last 1 'SfB:TeamsActiveCall' | Select-Object -Last 1
# Get Teams application process
$TeamsProcess = Get-Process -Name Teams -ErrorAction SilentlyContinue
If ($TeamsStatus -like "*Setting the taskbar overlay icon - Available*" -or ` # Check if Teams is running and start monitoring the log if it is
$TeamsStatus -like "*StatusIndicatorStateService: Added Available*") { If ($null -ne $TeamsProcess) {
$Status = "Available" If ($TeamsStatus -like "*Setting the taskbar overlay icon - Available*" -or `
Write-Host $Status $TeamsStatus -like "*StatusIndicatorStateService: Added Available*") {
} $Status = "Available"
ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Busy*" -or ` Write-Host $Status
$TeamsStatus -like "*StatusIndicatorStateService: Added Busy*" -or ` }
$TeamsStatus -like "*Setting the taskbar overlay icon - On the phone*") { ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Busy*" -or `
$Status = "Busy" $TeamsStatus -like "*StatusIndicatorStateService: Added Busy*" -or `
Write-Host $Status $TeamsStatus -like "*Setting the taskbar overlay icon - On the phone*") {
} $Status = "Busy"
ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Away*" -or ` Write-Host $Status
$TeamsStatus -like "*StatusIndicatorStateService: Added Away*") { }
$Status = "Away" ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Away*" -or `
Write-Host $Status $TeamsStatus -like "*StatusIndicatorStateService: Added Away*") {
} $Status = "Away"
ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Do not disturb *" -or ` Write-Host $Status
$TeamsStatus -like "*StatusIndicatorStateService: Added DoNotDisturb*" -or ` }
$TeamsStatus -like "*Setting the taskbar overlay icon - Focusing*" -or ` ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - Do not disturb *" -or `
$TeamsStatus -like "*StatusIndicatorStateService: Added Focusing*") { $TeamsStatus -like "*StatusIndicatorStateService: Added DoNotDisturb*" -or `
$Status = "Do not disturb" $TeamsStatus -like "*Setting the taskbar overlay icon - Focusing*" -or `
Write-Host $Status $TeamsStatus -like "*StatusIndicatorStateService: Added Focusing*") {
} $Status = "Do not disturb"
ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - In a meeting*" -or ` Write-Host $Status
$TeamsStatus -like "*StatusIndicatorStateService: Added InAMeeting*") { }
$Status = "In a meeting" ElseIf ($TeamsStatus -like "*Setting the taskbar overlay icon - In a meeting*" -or `
Write-Host $Status $TeamsStatus -like "*StatusIndicatorStateService: Added InAMeeting*") {
$Status = "In a meeting"
Write-Host $Status
}
} }
ElseIf ($TeamsStatus -like "*ain window*") { # Set status to Offline when the Teams application is not running
$Status = "Offline" Else {
Write-Host $Status $Status = "Offline"
Write-Host $Status
} }
If ($TeamsActivity -like "*Resuming daemon App updates*" -or ` If ($TeamsActivity -like "*Resuming daemon App updates*" -or `

Loading…
Cancel
Save