-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeamsCleanup.ps1
64 lines (50 loc) · 2.48 KB
/
TeamsCleanup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Step 1: 移除當前使用者的舊版 Teams
Write-Host "正在移除當前使用者的舊版 Teams..."
# 關閉所有 Teams 進程
Write-Host "正在關閉 Teams 進程..."
taskkill /F /IM Teams.exe /T 2> $null
# 移除 Microsoft Store 版 Teams(針對當前使用者)
Write-Host "正在移除 Microsoft Store 版 Teams..."
Get-AppxPackage *Microsoft.Teams* | Remove-AppxPackage
# 移除傳統版 Teams(針對當前使用者)
Write-Host "正在移除傳統版 Teams..."
winget uninstall --id Microsoft.Teams --silent --force 2> $null
# 清理 Teams 殘留檔案
Write-Host "清理所有 Teams 殘留檔案..."
Remove-Item -Path "$env:APPDATA\Microsoft\Teams" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Teams" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\ProgramData\Microsoft\Teams" -Recurse -Force -ErrorAction SilentlyContinue
# Step 2: 安裝最新版本的 Microsoft Teams(從 Microsoft Store 安裝)
Write-Host "正在安裝最新版本的 Microsoft Teams..."
winget source update # 更新 winget 來源
winget install --id Microsoft.Teams --silent --accept-source-agreements 2> $null
# Step 3: 啟動 Teams
Write-Host "正在啟動 Teams..."
# Teams 的安裝路徑
$teamsExePath = "$env:LOCALAPPDATA\Microsoft\Teams\current\Teams.exe"
# 檢查 Teams 是否已經安裝
if (Test-Path $teamsExePath) {
Write-Host "正在啟動 Teams..."
Start-Process -FilePath $teamsExePath
} else {
Write-Host "未能找到 Teams 安裝路徑,請手動安裝 Teams。"
}
# Step 4: 設定 Teams 為啟動項目(讓每個使用者登錄時自動啟動 Teams)
Write-Host "正在設定 Teams 為啟動項目..."
# 確保每個使用者的啟動資料夾存在
$startupPath = [System.Environment]::GetFolderPath('Startup')
# 檢查啟動資料夾並將 Teams 快捷方式添加到該資料夾
$teamsShortcutPath = "$startupPath\Teams.lnk"
# 檢查 Teams 是否已經在啟動項目中,若無則創建快捷方式
if (!(Test-Path $teamsShortcutPath)) {
Write-Host "正在創建 Teams 快捷方式..."
$wsh = New-Object -ComObject WScript.Shell
$shortcut = $wsh.CreateShortcut($teamsShortcutPath)
$shortcut.TargetPath = $teamsExePath
$shortcut.Save()
}
Write-Host "完成!Teams 已安裝並設定為啟動項目,且會在每次登入時啟動。"
Write-Host "Teams 已經在本次會話中啟動。"
# 等待使用者按下 Enter 鍵以結束腳本
Write-Host "按 Enter 鍵以結束..."
$null = Read-Host