当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] Microsoft Teams 卸载、重新安装和清理指南和脚本

作者:精品下载站 日期:2024-12-14 03:40:11 浏览:16 分类:玩电脑

Microsoft Teams 卸载、重新安装和清理指南和脚本


在安装和卸载方面,Microsoft Teams 与普通程序不同。 Microsoft Teams 的问题在于它是为每个用户安装的,位于用户的 AppData(有时是程序数据)中。除此之外,我们还有 Microsoft Teams 机器范围的安装程序,当用户登录时,它将自动安装 Teams。

使用 Microsoft Teams 清理问题可能非常具有挑战性。例如,我最近尝试为用户删除并重新安装 Teams。用户收到错误:每次更新 Microsoft Teams 时 Microsoft Teams 安装均失败

删除所有内容并重新安装 Teams 后,他最终得到了一个空白的 Teams 应用程序。因此,没有聊天历史记录,也没有更多的 Teams 频道(即使在线一切仍然可见)。

在本文中,我将向您提供一些删除和清理 Teams 的提示和脚本,以便您可以再次重新安装它。

利用这些有趣的 Microsoft Teams 背景让 Teams 变得更有趣

修复 Microsoft Teams 安装失败的问题

Microsoft Teams 最常见的错误之一是“安装失败”错误,当 Teams 尝试更新时可能会出现该错误。每次更新时都会出现此错误,并且非常烦人。

简单地重新安装 Teams 并不是解决方案。目前可以使用,但该错误可能会在下次更新时再次出现。

真正解决问题的唯一方法是删除本地缓存并重新启动 Microsoft Teams:

  1. 关闭微软团队
  2. Windows键 + R
  3. 输入 %appdata% 并按 Enter 键

[玩转系统] Microsoft Teams 卸载、重新安装和清理指南和脚本

  1. 打开文件夹Microsoft
  2. 删除文件夹团队

[玩转系统] Microsoft Teams 卸载、重新安装和清理指南和脚本

5. 重启团队

您还可以使用下面的 PowerShell 脚本来删除 Microsoft Teams 缓存。

卸载微软团队

我们从简单的部分开始,只需卸载 Microsoft Teams。有些人评论说,他们的 Microsoft Teams 在卸载后不断重新安装。这大多数时候是由机器范围安装程序引起的。

因此,要完全卸载 Microsoft Teams,您必须删除 Microsoft Teams 和 Teams 计算机范围安装程序。

  1. 打开设置> 应用程序> 应用程序和功能
  2. 搜索团队
  3. 删除所有应用程序(是的,我有两个机器范围的安装程序......不要问为什么)

[玩转系统] Microsoft Teams 卸载、重新安装和清理指南和脚本

使用 PowerShell 卸载 Microsoft Teams

我喜欢尽可能地自动化操作,所以当然,我们还有一个 PowerShell 脚本来卸载 Microsoft Teams。

该脚本将删除机器范围安装程序和 Microsoft Teams 自身。确保在提升模式下运行 PowerShell 脚本。您可以通过以管理员身份打开 PowerShell 来执行此操作

function unInstallTeams($path) {

	$clientInstaller = "$($path)\Update.exe"
	
	 try {
        $process = Start-Process -FilePath "$clientInstaller" -ArgumentList "--uninstall /s" -PassThru -Wait -ErrorAction STOP

        if ($process.ExitCode -ne 0)
		{
			Write-Error "UnInstallation failed with exit code  $($process.ExitCode)."
        }
    }
    catch {
        Write-Error $_.Exception.Message
    }

}

# Remove Teams Machine-Wide Installer
Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow

$MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
$MachineWide.Uninstall()

# Remove Teams for Current Users
$localAppData = "$($env:LOCALAPPDATA)\Microsoft\Teams"
$programData = "$($env:ProgramData)$($env:USERNAME)\Microsoft\Teams"


If (Test-Path "$($localAppData)\Current\Teams.exe") 
{
	unInstallTeams($localAppData)
		
}
elseif (Test-Path "$($programData)\Current\Teams.exe") {
	unInstallTeams($programData)
}
else {
	Write-Warning  "Teams installation not found"
}

该脚本将检查 Teams 的两个可能的安装位置,并在找到时将其删除。

如果您想为多个用户(在同一台计算机上)运行此脚本,则可以使用以下部分代替“删除当前用户的团队”部分:

# Get all Users
$Users = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"

# Process all the Users
$Users | ForEach-Object {
        Write-Host "Process user: $($_.Name)" -ForegroundColor Yellow

        #Locate installation folder
        $localAppData = "$($ENV:SystemDrive)\Users$($_.Name)\AppData\Local\Microsoft\Teams"
        $programData = "$($env:ProgramData)$($_.Name)\Microsoft\Teams"

        If (Test-Path "$($localAppData)\Current\Teams.exe") 
        {
	        unInstallTeams($localAppData)
		
        }
        elseif (Test-Path "$($programData)\Current\Teams.exe") {
	        unInstallTeams($programData)
        }
        else {
	        Write-Warning  "Teams installation not found for user $($_.Name)"
        }
}

卸载 Teams 计算机范围内的安装程序

需要明确的是,您可以安全地卸载 Teams 计算机范围内的安装程序。它所做的只是为每个登录的用户安装 Teams。

您可以在设置屏幕中或使用 PowerShell 脚本卸载 Teams 计算机范围内的安装程序。

  1. 打开设置> 应用程序> 应用程序和功能
  2. 搜索团队
  3. 卸载 Teams 计算机范围安装程序

[玩转系统] Microsoft Teams 卸载、重新安装和清理指南和脚本

您还可以使用 PowerShell 删除 Teams 计算机范围安装程序。如果您需要从多台计算机上删除它,这非常有用。确保在提升模式下运行 PowerShell 脚本。

您可以从开始菜单以管理员身份打开 PowerShell。

# Remove Teams Machine-Wide Installer
Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow

$MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
$MachineWide.Uninstall()

Microsoft Teams 清除缓存

因此,我有一次不得不为用户删除 Microsoft Teams,但重新安装 Teams 后却没有任何历史记录。解决此问题的唯一解决方案是清除 Microsoft Teams 的缓存。

问题是 Microsoft Teams 的缓存没有一个位置。我预计它会在漫游 AppData 中,但事实证明它不是唯一的位置。我们还需要清除 Chrome 和 Edge 缓存才能将其完全删除。

Mark Vale 已经创建了一个非常好的 PowerShell 脚本来清除 Microsoft Teams 缓存,因此我们将使用它:

# Author: Mark Vale

$clearCache = Read-Host "Do you want to delete the Teams Cache (Y/N)?"
$clearCache = $clearCache.ToUpper()

if ($clearCache -eq "Y"){
    Write-Host "Stopping Teams Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Teams | Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Teams Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Clearing Teams Disk Cache" -ForegroundColor Yellow

    try{
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\application cache\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\databases" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\gpucache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Indexeddb" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Local Storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\tmp" | Remove-Item -Confirm:$false
        Write-Host "Teams Disk Cache Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Stopping Chrome Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Chrome| Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Chrome Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing Chrome Cache" -ForegroundColor Yellow
    
    try{
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cookies" -File | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Web Data" -File | Remove-Item -Confirm:$false
        Write-Host "Chrome Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Stopping IE Process" -ForegroundColor Yellow
    
    try{
        Get-Process -ProcessName MicrosoftEdge | Stop-Process -Force
        Get-Process -ProcessName IExplore | Stop-Process -Force
        Write-Host "Internet Explorer and Edge Processes Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing IE Cache" -ForegroundColor Yellow
    
    try{
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 2
        Write-Host "IE and Edge Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Cleanup Complete... Launching Teams" -ForegroundColor Green
    Start-Process -FilePath $env:LOCALAPPDATA\Microsoft\Teams\current\Teams.exe
    Stop-Process -Id $PID
}

此脚本只会清除 Microsoft Teams 的缓存并在完成后重新启动 Teams。

您还可以结合清理和删除脚本来一次运行完成所有操作:

# Clearing Teams Cache by Mark Vale
# Uninstall Teams by Rudy Mens

$clearCache = Read-Host "Do you want to delete the Teams Cache (Y/N)?"
$clearCache = $clearCache.ToUpper()

$uninstall= Read-Host "Do you want to uninstall Teams completely (Y/N)?"
$uninstall= $uninstall.ToUpper()


if ($clearCache -eq "Y"){
    Write-Host "Stopping Teams Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Teams | Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Teams Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Clearing Teams Disk Cache" -ForegroundColor Yellow

    try{
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\application cache\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\databases" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\gpucache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Indexeddb" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Local Storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\tmp" | Remove-Item -Confirm:$false
        Write-Host "Teams Disk Cache Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Stopping Chrome Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Chrome| Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Chrome Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing Chrome Cache" -ForegroundColor Yellow
    
    try{
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cookies" -File | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Web Data" -File | Remove-Item -Confirm:$false
        Write-Host "Chrome Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Stopping IE Process" -ForegroundColor Yellow
    
    try{
        Get-Process -ProcessName MicrosoftEdge | Stop-Process -Force
        Get-Process -ProcessName IExplore | Stop-Process -Force
        Write-Host "Internet Explorer and Edge Processes Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing IE Cache" -ForegroundColor Yellow
    
    try{
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 2
        Write-Host "IE and Edge Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Cleanup Complete..." -ForegroundColor Green
}

if ($uninstall -eq "Y"){
    Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow
    $MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
    $MachineWide.Uninstall()


    function unInstallTeams($path) {

	$clientInstaller = "$($path)\Update.exe"
	
	 try {
        $process = Start-Process -FilePath "$clientInstaller" -ArgumentList "--uninstall /s" -PassThru -Wait -ErrorAction STOP

        if ($process.ExitCode -ne 0)
		{
			Write-Error "UnInstallation failed with exit code  $($process.ExitCode)."
        }
    }
    catch {
        Write-Error $_.Exception.Message
    }

    }


    #Locate installation folder
    $localAppData = "$($env:LOCALAPPDATA)\Microsoft\Teams"
    $programData = "$($env:ProgramData)$($env:USERNAME)\Microsoft\Teams"


    If (Test-Path "$($localAppData)\Current\Teams.exe") 
    {
	    unInstallTeams($localAppData)
		
    }
    elseif (Test-Path "$($programData)\Current\Teams.exe") {
	    unInstallTeams($programData)
    }
    else {
	    Write-Warning  "Teams installation not found"
    }

}

总结

我希望这些脚本可以帮助您删除和清理 Microsoft Teams。如果您想重新安装 Microsoft Teams,请务必查看这篇文章。

如果您有任何疑问,请在下面发表评论。

再次感谢 Mark Vale 提供的清理脚本!

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯