2024-02-10 20:00:00 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Nettoyage du cache de Microsoft Teams et des Credentials compte Microsoft pour le module Microsoft.AAD.BrokerPlugin
|
|
|
|
A lancer en admin
|
|
|
|
Peut nécessiter de lancer en désactivant les restrictions liées à la politique d'exécution des scripts sur certains PC au préalable :
|
|
|
|
Set-ExecutionPolicy Bypass -Scope Process
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
Suppression des fichiers de cache de MS Teams et des credentials du module Microsoft.AAD.BrokerPlugin
|
|
|
|
|
|
|
|
.PARAMETER <Parameter_Name>
|
|
|
|
-SamAccountName
|
|
|
|
|
|
|
|
.INPUTS
|
|
|
|
Aucun
|
|
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
Aucun
|
|
|
|
|
|
|
|
.NOTES
|
2024-02-12 20:00:00 +01:00
|
|
|
Version: 0.2.1
|
2024-02-10 20:00:00 +01:00
|
|
|
Author: Simon404
|
2024-02-12 20:00:00 +01:00
|
|
|
Creation Date: 2024-02-12
|
2024-02-10 20:00:00 +01:00
|
|
|
Purpose/Change: Script interactif avec vérification de l'existence du process de MS Teams (ancien et nouveau)
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
Clear-MSTeamsCache.ps1
|
|
|
|
#>
|
|
|
|
|
2024-02-12 20:00:00 +01:00
|
|
|
|
2024-02-10 20:00:00 +01:00
|
|
|
#---------------------------------------------------------[Initialisations]----------------------------------------
|
|
|
|
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param (
|
|
|
|
[Parameter(Mandatory=$true,Position = 0)]
|
|
|
|
[string]$SamAccountName
|
|
|
|
)
|
|
|
|
|
|
|
|
$MSTeamsNewProcessName = 'ms-teams'
|
2024-02-12 20:00:00 +01:00
|
|
|
$MSTeamsClassicProcessName = 'Teams'
|
2024-02-10 20:00:00 +01:00
|
|
|
|
2024-02-12 20:00:00 +01:00
|
|
|
$BasePath = $env:USERPROFILE | SplitPath -Parent
|
2024-02-10 20:00:00 +01:00
|
|
|
$AppDataMSTeamsRoamingFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Roaming\Teams"
|
|
|
|
$AppDataMSTeamsRoamingSubFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Roaming\Microsoft\Teams"
|
|
|
|
$AppDataAADPackageFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy"
|
|
|
|
$AppDataOneAuthFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Microsoft\OneAuth"
|
|
|
|
$AppDataIdentityCacheFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Microsoft\IdentityCache"
|
|
|
|
$FoldersToDelete = @($AppDataMSTeamsRoamingFolder,$AppDataMSTeamsRoamingSubFolder,$AppDataAADPackageFolder,$AppDataOneAuthFolder,$AppDataIdentityCacheFolder)
|
|
|
|
|
|
|
|
#---------------------------------------------------------[Fonctions]----------------------------------------
|
|
|
|
|
|
|
|
# Fermeture forcée du process MS Teams (Classic ou New)
|
|
|
|
function Stop-MSTeams {
|
2024-02-12 20:00:00 +01:00
|
|
|
$MSTeamsProcessList = Get-Process | Where-Object {(($_.ProcessName -eq "$MSTeamsClassicProcessName") -or ($_.ProcessName -eq "$MSTeamsNewProcessName") -and ($_.Company -eq "Microsoft Corporation"))} | Select-Object -ExpandProperty ProcessName
|
2024-02-10 20:00:00 +01:00
|
|
|
if ($MSTeamsProcessList) {
|
|
|
|
foreach ($MSTeamsProcessName in $MSTeamsProcessList) {
|
2024-02-12 20:00:00 +01:00
|
|
|
Write-Host -Object "Fermeture de $MSTeamsProcessName"
|
2024-02-10 20:00:00 +01:00
|
|
|
Stop-Process -Force -Name $MSTeamsProcessName
|
2024-01-10 20:00:00 +01:00
|
|
|
}
|
2024-02-10 20:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Affichage construction des chemins des répertoires de cache
|
|
|
|
function Write-CacheFolder {
|
|
|
|
foreach ($IndividualFolder in $FoldersToDelete) {
|
|
|
|
Write-Host Remove-Item -Recurse -Force -Path $IndividualFolder
|
2024-01-10 20:00:00 +01:00
|
|
|
}
|
2024-02-10 20:00:00 +01:00
|
|
|
}
|
2023-12-22 20:00:00 +01:00
|
|
|
|
2024-02-10 20:00:00 +01:00
|
|
|
# Demande confirmation de la suppression
|
|
|
|
function Read-ExecutionUserConfirm {
|
|
|
|
$Confirmation = Read-Host "Confirmer (y) ou (o) ?"
|
|
|
|
if (($Confirmation -eq 'y') -or ($Confirmation -eq 'o')) {
|
|
|
|
Write-Host "Lancement effacement cache"
|
|
|
|
} else {
|
|
|
|
$ScriptExitMessage = "Sortie du script"
|
|
|
|
Write-Host $ScriptExitMessage
|
|
|
|
exit
|
|
|
|
}
|
2024-01-10 20:00:00 +01:00
|
|
|
}
|
2023-12-22 20:00:00 +01:00
|
|
|
|
2024-02-10 20:00:00 +01:00
|
|
|
# Lancement suppression des répertoires
|
|
|
|
function Remove-CacheFolder {
|
|
|
|
foreach ($IndividualFolder in $FoldersToDelete) {
|
|
|
|
Remove-Item -Recurse -Force -Path $IndividualFolder
|
|
|
|
}
|
2023-12-22 20:00:00 +01:00
|
|
|
}
|
2024-01-10 20:00:00 +01:00
|
|
|
|
2024-02-10 20:00:00 +01:00
|
|
|
#---------------------------------------------------------[Exécution]----------------------------------------
|
2024-01-10 20:00:00 +01:00
|
|
|
|
2024-02-10 20:00:00 +01:00
|
|
|
Stop-MSTeams
|
|
|
|
Write-CacheFolder
|
|
|
|
Read-ExecutionUserConfirm
|
|
|
|
Remove-CacheFolder
|