Teams-AutoAnswerWithVideo.ps1

<#PSScriptInfo
 
.VERSION 1.0.0
 
.GUID 466203eb-89e4-45f9-ac66-6f91d410e4d3
 
.AUTHOR Aaron Guilmette
 
.COMPANYNAME Microsoft
 
.COPYRIGHT 2020
 
.TAGS teams video
 
.LICENSEURI
 
.PROJECTURI https://www.undocumented-features.com/2020/04/30/auto-answer-teams-call-with-video-and-powershell/
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
.DESCRIPTION
Auto-answer Teams with Video.
 
.PRIVATEDATA
 
#>


<#
.SYNOPSIS
Auto-answer Teams with Video.
 
.EXAMPLE
Put in user start-up scripts to auto-answer Teams with Video.
 
.NOTES
2020-06-23 Updated for PowerShell Gallery.
2020-04-30 Initial release.
#>


$Log = "$($env:APPDATA)\Microsoft\Teams\logs.txt"
While (Get-Content -Tail 100 $Log | ? { $_ -notmatch "TeamsPendingCall" })
{
    [array]$teamsarray = (get-process *teams*).Id
    foreach ($obj in $teamsarray)
    {
        $wshell = New-Object -ComObject wscript.shell
        $Result = $wshell.AppActivate($obj)
        $Result2 = $wshell.SendKeys('^+A')
        $SleepTime = 20
        $i = 1
        Foreach ($i in 1 .. $SleepTime)
        {
            Write-Progress -PercentComplete (($i / $SleepTime) * 100) -Activity "Waiting to check log file."
            sleep -seconds 1; $i++
        }
    }
}