PSADT To Detect Active MS Teams Call

Hi,

I have the following script in my PSADT whereby I only want the script to work if users are not in an active Zoom or MS Teams call. The script stops working as expected when a user is on an active zoom call however cannot get this to work when in an active teams call. The script stops working when it detects that the teams app is open in the background and not in a call like zoom.

## Test if Zoom, Teams or Skype meetings are active
        Write-log "Check for active Zoom or Teams call"
        If (get-process | where {$_.Name -match "zoom$|teams$"}){
            If (((Get-NetUDPEndpoint -OwningProcess (get-process | where {$_.Name -match "zoom$|teams$"}).Id -ErrorAction SilentlyContinue | Where {$_.LocalAddress -ne '127.0.0.1'} | measure).count) -gt 0) {
                Write-log "Active Zoom or Teams call detected. Exiting script and trying again on next schedule"
                exit-script -ExitCode 1618
            }
        }

What am I doing wrong?

Three things:

First, When you get the processes, use the list you have, don’t call Get-Process twice. There is no guarantee that when calling it a second time, the list of processes is the same.

Second, In my testing, when Teams is running it has a endpoint with :: as the local endpoint. When I was in a call, the there were multiple endpoints with other LocalAddresses

Lastly, it’s not a requirement, but you don’t need the measure \ count portion because the if condition will return $true if anything is returned. So if an NetUDPEndpoint is found from the Where-Object statement, then the if condition is true and will run the next statement. If there are no NetUDPEndpoints, then it returns $false. and nothing happens

## Test if Zoom, Teams or Skype meetings are active
Write-Log "Check for active Zoom or Teams call"
If ($procs = get-process | where {$_.Name -match "zoom$|teams$"}){
    If (Get-NetUDPEndpoint -OwningProcess $procs.Id -ErrorAction SilentlyContinue | Where-Object {($_.LocalAddress -ne '127.0.0.1') -or ($_.LocalAddress -ne '::')}) {
        Write-Log "Active Zoom or Teams call detected. Exiting script and trying again on next schedule"
        Exit-Script -ExitCode 1618
    }
}
1 Like

Excellent, excellent proposed solution. Learned something new today about Get-NetUDPEndpoint!

One tweak, however. Since you’re using not conditions, I believe you need to use -and instead of -or in terms of your conditional logic. My testing of this code was misfiring and declaring Teams to be in a meeting even when not.

If this cmdlet didn’t exist I think we’d be forced to using the Graph API which wouldn’t jive well with locally-executed packages, if at all. Very neat and will keep this snippet for the future!

## Test if Zoom, Teams or Skype meetings are active
Write-Log "Check for active Zoom or Teams call"
If ($procs = get-process | where {$_.Name -match "zoom$|teams$"}){
   If (Get-NetUDPEndpoint -OwningProcess $procs.Id -ErrorAction SilentlyContinue | Where-Object {($_.LocalAddress -ne '127.0.0.1') -and ($_.LocalAddress -ne '::')}) {
       Write-Log "Active Zoom or Teams call detected. Exiting script and trying again on next schedule"
       Exit-Script -ExitCode 1618
   }
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.