Files
wehub-resource-sync 3e779be6f3
CI / lint (push) Failing after 13m4s
CI / test (3.11, ubuntu-latest) (push) Failing after 2m4s
CI / test (3.13, ubuntu-latest) (push) Successful in 13m30s
CI / test (3.14, ubuntu-latest) (push) Successful in 17m21s
CI / test (3.12, ubuntu-latest) (push) Successful in 17m55s
CI / discover-apps-ps (push) Successful in 1m56s
CI / test (3.9, ubuntu-latest) (push) Successful in 13m17s
CI / test (3.10, ubuntu-latest) (push) Successful in 26m21s
CI / audit (push) Successful in 13m38s
Deploy site / deploy (push) Has been cancelled
CI / test (3.14, ubuntu-24.04-arm) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:32:37 +08:00

54 lines
1.9 KiB
PowerShell

# SPDX-License-Identifier: MIT
# find_teams.ps1 - Locate the New Teams (MSIX) executable on the guest.
# Prints absolute path to stdout (exit 0); prints nothing on failure (exit 1).
# Usage: powershell -NoProfile -ExecutionPolicy Bypass -File find_teams.ps1
$ErrorActionPreference = "SilentlyContinue"
function Write-Path {
param([string]$Path)
if ([string]::IsNullOrWhiteSpace($Path)) { return $false }
if (-not (Test-Path -LiteralPath $Path)) { return $false }
Write-Output $Path
return $true
}
# 1. Preferred: stable App Execution Alias installed by MSIX.
$alias = Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps\ms-teams.exe"
if (Write-Path $alias) { exit 0 }
# 2. Query the MSIX package directly (New Teams, 2024+).
try {
$pkg = Get-AppxPackage -Name "MSTeams" -ErrorAction SilentlyContinue |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($pkg) {
$candidate = Join-Path $pkg.InstallLocation "ms-teams.exe"
if (Write-Path $candidate) { exit 0 }
# Some builds ship the exe under a subdirectory.
$fallback = Get-ChildItem -Path $pkg.InstallLocation -Filter "ms-teams.exe" `
-Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($fallback -and (Write-Path $fallback.FullName)) { exit 0 }
}
} catch {
# No Appx support on this edition; fall through.
}
# 3. Last resort: PATH lookup via where.exe (covers classic Teams installers
# that drop ms-teams.exe into a PATH-visible directory).
try {
$whereOutput = & where.exe ms-teams.exe 2>$null
if ($LASTEXITCODE -eq 0 -and $whereOutput) {
$first = ($whereOutput -split "`r?`n" | Where-Object { $_ })[0]
if (Write-Path $first) { exit 0 }
}
} catch {
# where.exe absent; fall through.
}
# 4. Classic Teams install path (pre-2024).
$classic = Join-Path $env:LOCALAPPDATA "Microsoft\Teams\current\Teams.exe"
if (Write-Path $classic) { exit 0 }
exit 1