November 2018
Intermediate to advanced
566 pages
17h 15m
English
We will simply build on the previous recipe to save ourselves some time and effort. The changes from the script in the previous recipe have been emboldened:
# Change this to match ./path/of/your/choice/ from the aforementioned scripts
$LabPath = "$HOME/random"
$Today = Get-Date
$TotalFileSize = 0
$AllFiles = Get-ChildItem $LabPath -Recurse -File $FilesToDelete = $AllFiles | Where-Object {[math]::Floor(($Today - $_.LastWriteTime).TotalDays) -eq 30} Write-Host "The following files will be deleted:" Write-Host $FilesToDelete.FullName foreach ($File in $FilesToDelete) { $TotalFileSize += $File.Length Remove-Item -Path $File -WhatIf ...Read now
Unlock full access