how to delete directory path in user profiles

Hi,

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.

#Single User

$userpath1 = “C:\Users\username\AppData\Local”

#All Users

$userpath2 = “C:\Users*\AppData\Local”

#All Roaming Profiles

$userpath3 = “\Server\Share\RoamingProfiles*\AppData\Local”

Remove-Item “$userpath1\Folder” -Force -Recurse

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.

PowerShell
10 lines
<textarea class="ace_text-input" style="opacity: 0; height: 17.6px; width: 6.59775px; left: 51px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
4
5
6
7
8
9
10
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.

Executed locally, you could do something like so:

Get-Item -Path "C:\Users\*\AppData\Roaming\*Teams" | Remove-Item -Recurse -Force -WhatIf

Remove the -WhatIf when you are ready to make changes to a test system prior to utilizing in Prod

[quote quote=214845]Executed locally, you could do something like so:

<textarea class="ace_text-input" style="opacity: 0; height: 17.6px; width: 6.59775px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
Get-Item -Path "C:\Users\*\AppData\Roaming\*Teams" | Remove-Item -Recurse -Force -WhatIf
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Remove the -WhatIf when you are ready to make changes to a test system prior to utilizing in Prod

[/quote]

Will try that - thanks!