Author Posts

May 6, 2014 at 8:26 pm

I am trying to clear the 'Downloads' folder from all of our user profiles, the structure is:


I can't figure out how to empty the contents of the 'Downloads' folder from user profiles without having a separate line for each different username..

Batches like del "\\server\share\UPMProfiles\*\UPM_Profile\Downloads" don't work.

Any suggestions would be greatly appreciated.


May 7, 2014 at 5:15 am

You could use the wildcard and pipe the results to Remove-Item.

dir \\server1\c$\users\*\downloads\* | where LastWriteTime -lt $cutoff | rm -Confirm

In this example, I removed files. But you could also remove whole directories. You will want to use the -Recurse and -Force switches.

May 7, 2014 at 12:45 pm

# Remember to remove -Whatif parameter when you're ready to actually delete them
Get-ChildItem \\server\share\UPMProfiles\*\UPM_Profile\Downloads\*.* | ForEach-Object {Remove-Item $_.Fullname -WhatIf}

# but the trick you were missing is the Foreach-Object