Auto-Answer Teams call with Video and PowerShell

5/5 - (1 vote)

UPDATE: An updated version script is now available on the PowerShell Gallery at https://www.powershellgallery.com/packages/Teams-AutoAnswer/.

Today, while working with my esteemed colleague Stephen Jones, we were discussing a need for some of our customers to auto-answer Teams with a video call.  This has a lot of practical scenarios, such as judicial, hospital, and corrections facilities.

A similar feature was available in Skype for Business.  Currently, there’s not a corresponding feature for Teams (though it’s on the roadmap).

After kicking around a few ideas, this is what we came up with:

$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++
        }
    }
}

Basically, it monitors the Teams log file for a “TeamsPendingCall” entry and then using the oldest-of-old-school methods, calling the VBScript WShell AppActivate method to make the Teams window active (though we don’t know which one, so we’re just gonna cycle through all of them) and then sending it the Ctrl+Shift+A hotkey sequence (the “Auto-answer a call with video” hotkey combo for Teams).

You can save this as a .PS1 and add it to a user start-up (since Teams needs to be running and signed in).  It’ not glamourous, and definitely not supported, but it is workable.

I’d love to hear comments on it!

author avatar
Aaron Guilmette
Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese.

3 Replies to “Auto-Answer Teams call with Video and PowerShell”

  1. It sounds like a formatting issue in saving it? Try saving the file as ANSI in notepad or copy/paste into Windows PowerShell ISE and save. If you’re still having problems, send me an email at aaron.guilmette@microsoft.com and I’ll respond with it via email.

    Have you tried using the “copy” button at the top of the script and pasting it into either Notepad or the PowerShell ISE?

  2. Thank you. We are looking to do this to help doctors round Covid Patients. But I keep running into the following error when running the script. If we can get this figured out it will immensely help our physicians stay safe during this pandemic and potentially save more lives.

    At C:\ps\TeamsAutoAnswer.ps1:5 char:19
    +   foreach ($obj in $teamsarray)
    + ~~
    Unexpected token ‘in’ in expression or statement.
    At C:\ps\TeamsAutoAnswer.ps1:5 char:18
    +   foreach ($obj in $teamsarray)
    + ~
    Missing closing ‘)’ in expression.
    At C:\ps\TeamsAutoAnswer.ps1:3 char:1
    + {
    + ~
    Missing closing ‘}’ in statement block or type definition.
    At C:\ps\TeamsAutoAnswer.ps1:5 char:33
    +   foreach ($obj in $teamsarray)
    + ~
    Unexpected token ‘)’ in expression or statement.
    At C:\ps\TeamsAutoAnswer.ps1:12 char:25
    +       Foreach ($i in 1..$SleepTime)
    + ~~
    Unexpected token ‘in’ in expression or statement.
    At C:\ps\TeamsAutoAnswer.ps1:12 char:24
    +       Foreach ($i in 1..$SleepTime)
    + ~
    Missing closing ‘)’ in expression.
    At C:\ps\TeamsAutoAnswer.ps1:6 char:9
    +     {
    + ~
    Missing closing ‘}’ in statement block or type definition.
    At C:\ps\TeamsAutoAnswer.ps1:12 char:41
    +       Foreach ($i in 1..$SleepTime)
    + ~
    Unexpected token ‘)’ in expression or statement.
    At C:\ps\TeamsAutoAnswer.ps1:16 char:9
    +     }
    + ~
    Unexpected token ‘}’ in expression or statement.
    At C:\ps\TeamsAutoAnswer.ps1:17 char:1
    + }
    + ~
    Unexpected token ‘}’ in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Comments are closed.