Empty Downloads folder for all users script

Andy Martin
Member
I'm looking for a script that could be ran at regular intervals to empty all downloads folders (standard windows 10 default downloads location) of all local user profiles with provided local admin credentials.
Tagged:
4
Comments
-
I would also assume it should delete the recycling bin contents after as well.
0 -
I was able to script this myself using executepowershell ps1 file.
The powershell script is as follows:
foreach($userfolder in (Get-ChildItem c:\users)){
if(Test-Path "C:\Users\$($userfolder.name)\Downloads"){
$path = "C:\Users\$($userfolder.name)\Downloads"
Get-ChildItem -Path $path -Recurse| Foreach-object {Remove-item -Recurse -path $_.FullName }
}else{
Write-Warning "Folder not found for $($userfolder.name)"
}
}
For the procedure I used impersonateUser and admin as the user, with local admin password, and domain blank.
Then executePowershell below pointing to the location of the ps1 file.
Works excellent.
0
This discussion has been closed.
Categories
Join The Community