Teams-AutoAnswer.ps1

<#PSScriptInfo
 
.VERSION 2.0
 
.GUID a4fbf04d-f10b-47bb-b427-90138fb75d0e
 
.DESCRIPTION Auto-answer Microsoft Teams calls.
 
.AUTHOR Aaron Guilmette
 
.COMPANYNAME Microsoft
 
.COPYRIGHT 2021
 
.TAGS Teams auto-answer
 
.LICENSEURI
 
.PROJECTURI https://www.undocumented-features.com/2021/05/25/update-to-teams-autoanswerwithvideo-script/
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
#>


<#
.SYNOPSIS
Auto-answer Microsoft Teams calls.
 
.PARAMETER CallType
Select which type of autoanswer type to use (video or audio)
 
.EXAMPLE
.\Teams-AutoAnswer.ps1 -CallType Video
Auto-answer Teams calls with Video.
 
.LINK
https://www.undocumented-features.com/2016/09/08/activesync-device-and-user-report-for-office-365-d-mt-and-exchange-2010/
 
.NOTES
- 2021-04-16 - Added video and audio parameters.
- 2021-05-25 - Incorporated reliability updates from mmmorsy[at]mantracgroup[dot]com
- 2020-04-16 - Original release
#>


param(
    [ValidateSet("Audio", "Video")]
    [string]$CallType = "Video",
    $Log = "$($env:APPDATA)\Microsoft\Teams\logs.txt"
)

$w = 1
While ($w = 1)
{
    $SleepTime = 3
    $i = 1
    Foreach ($i in 1 .. $SleepTime)
    {
        Write-Progress -PercentComplete (($i / $SleepTime) * 100) -Activity "Waiting to check log file."; sleep -seconds 1; $i++
    }
    $Call = Get-Content -Tail 50 $Log | ? { $_ -match "TeamsPendingCall" }
    If ($Call -ne $null)
    {
        [array]$teamsarray = (get-process *teams*).Id
        foreach ($obj in $teamsarray)
        {
            $wshell = New-Object -ComObject wscript.shell
            $Result = $wshell.AppActivate($obj)
            switch ($CallType)
            {
                Audio { $Result2 = $wshell.SendKeys('^+S') }
                Video { $Result2 = $wshell.SendKeys('^+A') }
                Default { $Result2 = $wshell.SendKeys('^+A') }
            }
            
        }
    }
}