mirror of
https://github.com/acedanger/shell.git
synced 2025-12-05 21:40:12 -08:00
8 lines
537 B
PowerShell
8 lines
537 B
PowerShell
$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 |