Requests for Automation

Empty Downloads folder for all users script

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.

This request was archived: Solved by user in comment

Discussion
Gravatar for Andy Martin
Andy Martin 8 months ago

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.

Gravatar for Andy Martin
Andy Martin 9 months ago

I would also assume it should delete the recycling bin contents after as well.

Details

  • Request Archived
  • 0 Votes
  • 2 Comments
  • Open for 9 months
  • Created by Andy Martin