Teams-AutoAnswer.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<#PSScriptInfo
 
.VERSION 2.0.1
 
.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-09-22 - Updated encoding to attempt to resolve errors on some platforms.
- 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') }
            }
            
        }
    }
}