PSADT 检测活跃的 MS 团队呼叫

PSADT To Detect Active MS Teams Call

我在这个网站上的第一个 post:)

我的 PSADT 中有以下脚本,我只希望该脚本在用户不在活动的 Zoom 或 MS Teams 通话中时起作用。当用户正在进行活动缩放通话时,脚本会按预期停止工作,但在进行活动团队通话时无法使其正常工作。当检测到团队应用程序在后台打开而不是在像缩放这样的调用中时,脚本停止工作。

 ## 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
            }
        }

我做错了什么?

欢迎来到堆栈溢出:)

根据团队情况;我在我的机器上测试了你的代码,发现如果应用程序在后台打开并且你的机器上启用了 IPv6,if 条件将始终匹配

这是由于IPv6地址::根据这个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          
      

所以你也用 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 '::'} 

代码应该是:

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