I found and modified this code to get the recent files and remove any that were made on the day the script is run:
#remove from past day
$limit = (Get-Date).AddDays(-1)
$path = "$($env:USERPROFILE)AppDataRoamingMicrosoftWindowsRecent"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Though I can check the folder manually and see that it has the files I want. I verified that the USERPROFILE value is correct as well by setting it to a variable and echoing it.
Despite everything seeming to be correct, it somehow removes my Quick Access shortcuts and NOT the files.
1
Try this code, this should solve your problem:
$PathToFolder = "$($env:USERPROFILE)AppDataRoamingMicrosoftWindowsRecent"
$LimitTime = (Get-Date).AddDays(-1)
# Delete the files based on the limit time
Get-ChildItem -Path $PathToFolder -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -gt $LimitTime } | Remove-Item -Force
Ikkxeer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.