Schedule a task to periodically delete certain folders of non admin user

P

PrashantDesaiHN

Hi friends, I have a windows 10 home premium computer with two users, one admin (controlled by me) and one non-admin user that I want to make for friends. The user will be local to my computer. I want to accomplish two things:
1) every 48 hours I want a powershell script to run that will delete Downloads, Desktop, Music, Pictures and Videos folders of the non-admin user.

2) Every day at 11:00 PM I want a powershell script to run that will log off the non-admin user if not already logged off.


I have tried to do the following:

I created a powershell script like this

Remove-Item -Path $env:UserProfile\Downloads\ -Recurse -Force
Remove-Item -Path $env:UserProfile\Desktop\ -Recurse -Force
Remove-Item -Path $env:UserProfile\Pictures\ -Recurse -Force
Remove-Item -Path $env:UserProfile\Videos\ -Recurse -Force
Remove-Item -Path $env:UserProfile\Music\ -Recurse -Force

Saved it as remove-folders-48hrs.ps1 in C:\program_files\Windows Powershell\scripts\ (C:\ of admin user)


Then I created the following task:

afab25af-f908-48f7-9374-87ea88d81258?upload=true.png


ede01fbe-1196-449b-bf16-41337153e0ff?upload=true.png


5ebcad0c-3908-40e0-a88e-f5783e89e324?upload=true.png


6963fcb6-7c85-4b6f-970a-6e68d8f07489?upload=true.png


4ef359e5-d194-46a0-b862-d0ee481cdd05?upload=true.png


6cd4a3c7-bc13-4879-8207-2efc13978de1?upload=true.png

Update: I changed the username to sam_and_jimmy.


Its not deleting the folder contents. I see the task running but when I log into the non-admin user the files are still there.


I haven't even tried to make the log off script work.


Any help on this will be greatly appreciated.


Thank you very much

Continue reading...
 
Back
Top Bottom