Update to Teams-AutoAnswerWithVideo Script

Update to Teams-AutoAnswerWithVideo Script

  •  
  •  
  •  
  •  
  •  
  •  

Nearing the height of the COVID pandemic here in the U.S., I bashed together a script to help customers auto-answer Teams calls with video.  You can find the original here: Auto-Answer Teams Call with Video and PowerShell. The premise was quite simple: monitor the Teams log file for an incoming call entry and then send the Teams hotkey sequence to answer.

I later revisited it for another project (integrating this script with Dynamics 365), adding a whole bunch of bells and whistles (such as screen scraping and Azure Cognitive Services), but never went back to update the original script with some of my key learnings.

One of my peers in the community, Mahmoud Morsy, ran into some of the same issues that I did when I was integrating the script.  He made some changes to allow it to work much more reliably, so I’ve posted them here:

$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)
        $Result2 = $wshell.SendKeys('^+S') 
     }
  }
}

The important piece to note switching the order of some things in the loop to make sure Teams is the Active Window (the same solution I came up with separately).  Great minds think alike (or at least run in similar circles).

You can deploy this to your machines using Install-Script -Name TeamsAutoAnswer or by visiting the PowerShell Gallery (https://www.powershellgallery.com/packages/Teams-AutoAnswer/2.0).

Great work, Mahmoud!

Published by 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.

Reader Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.