Im trying to make a script on a users pc that will run a powershell script once a week and clear out the contents of a users download folder.
i have tried the following scripts but cant get them to work.. Im not to familiar with powershell, So forgive me if the answer is easy I have tried the following scripts they will work with users temp folder but when i try to change it to downloads folder.
$CutOffDate = (Get-Date).AddDays(-7)
$AllTemp = "$($Env:Downloads.Replace("$Env:Username",'*'))"
Get-ChildItem -path $AllTemp -Recurse |
Where-Object {$_.CreationTime -lt $CutOffDate} |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
and
$CutOffDate = (Get-Date).AddDays(-7)
Get-ChildItem -Path "C:Users*Downloads*.*" | Where-Object { $_.CreationTime -lt $CutOffDate } | Remove-Item
The first script gives errors and the second one says permission denied when I use a basics user profile. However if I use admin profile it wants to delete downloads content from admin user and not basic user. So im unsure what do to can anyone help?