I am trying to figure out how to remove the directories called “Microsoft Teams” & “Teams” and everything in them. The paths are:
C:\Users\username\AppData\Roaming\Microsoft Teams
C:\Users\username\AppData\Roaming\Microsoft\Teams
I found this works locally on my system:
Remove-Item -path c:\Users\username\AppData\Roaming\Microsoft Teams -Recurse
Remove-Item -path c:\Users\username\AppData\Roaming\Teams -Recurse
What I’m not sure how to do, is remove the directories called “Microsoft Teams” & “Teams” as well AND since I’m going to use this remotely on other systems, I need the ‘username’ portion of the path in the C:\Users directory (user profile), to be a wildcard or something I’m thinking?
Thanks for any help/suggestions/resources y’all might offer.
This one works like a charm for me. I’ve got similar folders for some apps that I need to delete every now and again. Including files and folders from roaming profiles.
Is the intention to delete the directories on all profiles on a remote system or a specific user? You can use a wildcard to find all profiles that have Teams folder and pipe that to Remove-Item, but you need to be careful with *Teams as it would match anything that started with Teams on a system. If you want to specify a user, this can be done if that is a requirement.
PS C:\WINDOWS\system32> Get-Item -Path "C:\Users\*\AppData\Roaming\*Teams"
Directory: C:\Users\rasim\AppData\Roaming
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/11/2019 1:54 PM Microsoft Teams
How are you connecting to these computers? Invoke-Command, UNC path, executing in RDP for troubleshooting?
[quote quote=214818]Is the intention to delete the directories on all profiles on a remote system or a specific user? You can use a wildcard to find all profiles that have Teams folder and pipe that to Remove-Item, but you need to be careful with *Teams as it would match anything that started with Teams on a system. If you want to specify a user, this can be done if that is a requirement.
How are you connecting to these computers? Invoke-Command, UNC path, executing in RDP for troubleshooting?
[/quote]
Hi Rob,
Thank for the help - the intention is to remove the C:\Users~\AppData\Roaming\Microsoft Teams dir and the C:\Users~\AppData\Roaming\Teams dir for all users on a given system. We would execute when remoting in to the system, so local command line probably.