diff --git a/remove-files.ps1 b/remove-files.ps1 new file mode 100644 index 0000000..55a3a92 --- /dev/null +++ b/remove-files.ps1 @@ -0,0 +1,8 @@ +$limit = (Get-Date).AddDays(-60) +$path = "\\peranda-nas\media\backups\docker-data" + +# Delete files older than the $limit. +Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | 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 \ No newline at end of file