'Delete all folders in appdata/local except /microsoft/teams

\

i have this script that deletes c:\users\xxx\appdata\local i want to delete all folders under local except appdata\local\micrsoft\teams

# Get a list of all local profiles on the target machine # 
$users = Get-ChildItem c:\users
foreach ($user in $users){
$folder = "C:\users\" + $user +"\AppData\Local"
Remove-Item $folder -Recurse -Force -ErrorAction SilentlyContinue
}


Solution 1:[1]

it was easy actually just needed some research

# Get a list of all local profiles on the target machine # 
$users = Get-ChildItem c:\users
foreach ($user in $users){
$folder = "C:\users\" + $user +"\AppData\Local"
Get-ChildItem -Path $folder -Exclude microsoft | Remove-Item -Recurse -Force
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ahmed lidingo