How do I use Powershell to write a script to automatically clean the history of actions in a user's recent folder?

tj_zero 65 Reputation points
2023-09-07T02:40:21.4766667+00:00

Public PCS are easy to leak because they forget to clean operation records; Therefore, I want to write a Powershell script to put in the Windows startup folder, execute before displaying the system desktop, and clean the history of the last operation;

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Konstantinos Passadis 19,586 Reputation points MVP
    2023-09-11T23:08:24.3133333+00:00

    Hello @tj_zero !

    Welcome to Microsoft QnA!

    Please try :

    # Clean Recent Items

    $recent = [System.IO.Path]::Combine($env:APPDATA, 'Microsoft\Windows\Recent')

    Remove-Item "$recent*" -Force

    # Clean Temp Directory

    $temp = $env:TEMP

    Remove-Item "$temp*" -Force

    # Clear Event Logs (requires elevated privileges)

    Get-EventLog -LogName * | ForEach { Clear-EventLog -LogName $_.Log }

    # Additional cleanup can be added as needed

    Next

    Create a Task with Highest Privileges to run the script on user logon!

    User's image

    You might need to run this line also once:

    • Open PowerShell as an Administrator.
    • Run Set-ExecutionPolicy RemoteSigned.

    I hope this helps!

    Kindly set the answer as accepted and upvote or post your feedback !

    Regards

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.