Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PSADT To Detect Active MS Teams Call

My first post on this website :)

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?

like image 797
Jahed Avatar asked Oct 15 '25 07:10

Jahed


1 Answers

welcome to stack overflow :)

According to the case of teams; I tested your code on my machine and found that the if condition will always match if the app is opened in background and IPv6 is enabled on your machine

This is due to the IPv6 address :: which represent according to this Link

all IPv6 addresses on the local machine

PS C:\Windows\system32> Get-NetUDPEndpoint -OwningProcess (get-process | where {$_.Name -match "zoom$|teams$"}).Id -ErrorAction SilentlyContinue

LocalAddress                             LocalPort      
------------                             ---------      
::                                       58673          
::                                       54846          
      

so you to exclude also :: with 127.0.0.1

Get-NetUDPEndpoint -OwningProcess (get-process | where {$_.Name -match "zoom$|teams$"}).Id -ErrorAction SilentlyContinue | Where {$_.LocalAddress -ne "127.0.0.1" -and $_.LocalAddress -ne '::'} 

and the code should be:

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" -and $_.LocalAddress -ne '::'}  | measure).count) -gt 0) {
                Write-log "Active Zoom or Teams call detected. Exiting script and trying again on next schedule"
                exit-script -ExitCode 1618
            }
        }
like image 59
Mahmoud Moawad Avatar answered Oct 19 '25 05:10

Mahmoud Moawad