130 lines
4.5 KiB
PowerShell
130 lines
4.5 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Nettoyage du cache de Microsoft Teams et des Credentials compte Microsoft pour le module Microsoft.AAD.BrokerPlugin
|
|
|
|
.DESCRIPTION
|
|
Suppression des fichiers de cache de MS Teams et des credentials du 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
|
|
|
|
.PARAMETER SamAccountName
|
|
Nom du répertoire du profil utilisateur sur lequel agir
|
|
|
|
.INPUTS
|
|
Aucun
|
|
|
|
.OUTPUTS
|
|
Aucun
|
|
|
|
.NOTES
|
|
Version: 0.2.2
|
|
Author: Simon404
|
|
Creation Date: 2024-02-21
|
|
Purpose/Change: Script interactif avec vérification de l'existence du process de MS Teams (ancien et nouveau)
|
|
|
|
.EXAMPLE
|
|
Clear-MSTeamsCache.ps1 -SamAccountName userprofile
|
|
|
|
.LINK
|
|
https://forge.chapril/Simon404
|
|
|
|
#>
|
|
|
|
|
|
#---------------------------------------------------------[Initialisations]----------------------------------------
|
|
|
|
#TODO(Simon404): passage en Module
|
|
[CmdletBinding()]
|
|
Param (
|
|
[Parameter(Mandatory=$true, ValueFromPipeline = $true, Position = 0)]
|
|
[string]$SamAccountName
|
|
)
|
|
|
|
function Clear-MSTeamCache {
|
|
|
|
|
|
$global:MSTeamsNewProcessName = 'ms-teams'
|
|
$global:MSTeamsClassicProcessName = 'Teams'
|
|
$global:CompanyName = "Microsoft Corporation"
|
|
|
|
$global:BasePath = $env:USERPROFILE | Split-Path -Parent
|
|
$global:AppDataMSTeamsRoamingFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Roaming\Teams"
|
|
$global:AppDataMSTeamsRoamingSubFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Roaming\Microsoft\Teams"
|
|
$global:AppDataAADPackageFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy"
|
|
$global:AppDataOneAuthFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Microsoft\OneAuth"
|
|
$global:AppDataIdentityCacheFolder = Join-Path -Path $BasePath -ChildPath "$SamAccountName\AppData\Local\Microsoft\IdentityCache"
|
|
$global:FoldersToDelete = @($AppDataMSTeamsRoamingFolder,$AppDataMSTeamsRoamingSubFolder,$AppDataAADPackageFolder,$AppDataOneAuthFolder,$AppDataIdentityCacheFolder)
|
|
}
|
|
|
|
#---------------------------------------------------------[Fonctions]----------------------------------------
|
|
|
|
# Vérification de l'exécution sous Windows
|
|
function Test-OperatingSystem {
|
|
$OSIdentifier = Get-ChildItem -Path Env: |
|
|
Where-Object { $_.Name -eq "OS" }
|
|
if ($OSIdentifier.Value-eq "Windows_NT") {
|
|
Write-Host -Object "Lancement dans environnement Windows OK"
|
|
} else {
|
|
Write-Host -Object "Système d'exploitation non supporté"
|
|
}
|
|
}
|
|
|
|
# Demande confirmation de la suppression
|
|
#TODO(Simon404): passer le choix de l'utilisateur en paramètre de fonction
|
|
function Select-ExecutionUserConfirm {
|
|
$ConfirmationMessage = "Confirmer (o) ou (y) ? | Quitter (q)"
|
|
$StartFunctionMessage = "Lancement de l'action"
|
|
$ExitScriptMessage = "Sortie du script"
|
|
$SkipFunctionMessage = "Poursuite de l'execution du script à l'étape suivante"
|
|
|
|
$Confirmation = Read-Host -Prompt $ConfirmationMessage
|
|
|
|
if (($Confirmation -eq 'o') -or ($Confirmation -eq 'y')) {
|
|
Write-Host $StartFunctionMessage
|
|
} elseif ($Confirmation -eq 'q') {
|
|
Write-Host $ScriptExitMessage
|
|
exit
|
|
} else {
|
|
Select-ExecutionUserConfirm
|
|
}
|
|
}
|
|
|
|
# Fermeture forcée du process MS Teams (Classic ou New)
|
|
function Stop-MSTeams {
|
|
Write-Host -Object "Action : arrêt de MS Teams"
|
|
Select-ExecutionUserConfirm
|
|
$MSTeamsProcessList = Get-Process | Where-Object {(($_.ProcessName -eq "$MSTeamsClassicProcessName") -or ($_.ProcessName -eq "$MSTeamsNewProcessName") -and ($_.Company -eq "$CompanyName"))} | Select-Object -ExpandProperty ProcessName
|
|
if ($MSTeamsProcessList) {
|
|
foreach ($MSTeamsProcessName in $MSTeamsProcessList) {
|
|
Write-Host -Object "Fermeture de $MSTeamsProcessName"
|
|
Stop-Process -Force -Name $MSTeamsProcessName
|
|
}
|
|
}
|
|
}
|
|
|
|
# Affichage construction des chemins des répertoires de cache
|
|
function Write-CacheFolder {
|
|
foreach ($IndividualFolder in $FoldersToDelete) {
|
|
Write-Host Remove-Item -Recurse -Force -Path $IndividualFolder
|
|
}
|
|
}
|
|
|
|
# Lancement suppression des répertoires
|
|
function Remove-CacheFolder {
|
|
foreach ($IndividualFolder in $FoldersToDelete) {
|
|
Remove-Item -Recurse -Force -Path $IndividualFolder
|
|
}
|
|
}
|
|
|
|
#---------------------------------------------------------[Exécution]----------------------------------------
|
|
|
|
Clear-MSTeamCache
|
|
Test-OperatingSystem
|
|
Stop-MSTeams
|
|
Write-CacheFolder
|
|
Select-ExecutionUserConfirm
|
|
Remove-CacheFolder
|
|
|
|
#TODO(Simon404): vérifier fonctions à exporter pour module
|