Empty Downloads folder for all users script

Andy Martin
Andy Martin Member
edited January 24 in Request
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
4 votes

Shipped · Last Updated

solution provided by Andy Martin

4
4 votes

Needs Review · Last Updated

Comments

  • Andy Martin
    Andy Martin Member
    edited September 2019

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

  • Andy Martin
    Andy Martin Member
    edited September 2019

    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.

This discussion has been closed.