
Now or Then every Sys Admin needs to delete old Tempfiles or Archives with too much Junkfiles.
I created a Powershell script which deletes old Files and Folders older than a certain time.
I use it within a Scheduledtask and run it every Month. And here it ist, have fun with it 😉
1 2 3 4 5 6 7 8 |
$date = (Get-Date).AddDays(-30) $path = "C:\inetpub\wwwroot\SOLIDWORKSPDM\Web2\Content\tempFiles" # Delete files older than the $date todaysdate minus here 30 days Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $date } | Remove-Item -Force # Delete any empty directories left behind after deleting the old files Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse |
Error: Contact form not found.