Script to delete all users APPDATA\Local\Microsoft\Edge and OneDrive folders

I need a script that will delete the folders “Edge” and “OneDrive” in the c:\users<user>\AppData\Local\Microsoft for all users using the system account.
For example:

c:\users\user1\appdata\local\microsoft\Edge
c:\users\user1\appdata\local\microsoft\OneDrive

c:\users\user2\appdata\local\microsoft\Edge
c:\users\user2\appdata\local\microsoft\OneDrive

c:\users\user\appdata\local\microsoft\Edge
c:\users\user\appdata\local\microsoft\OneDrive

hi @PremJKumar

please assist this script request.

thank you

Hi @bravonet ,

Thanks for your script request. We have created an internal task " CS-61792" to assist your script.

Kind Regards,
PremJK

Hi @bravonet ,

Please check your Inbox for private messages, where we shared the script in JSON file.
Please try and provide your feedback, after your approval, we will upload it in the backend.

We have added a Retry Mechanism:
retry_delete_folder: This function will attempt to delete the folder up to 3 times (retries=3), with a 5-second delay (delay=5) between each attempt. You can adjust these values as needed.
If the deletion fails (due to locked files), it will wait for a brief period and try again

Kind Regards,
PremJK

Thank you for the script. It is working great and as expected.
Best regards,

Rom.

1 Like