%3CLINGO-SUB%20id%3D%22lingo-sub-1255317%22%20slang%3D%22en-US%22%3EPowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1255317%22%20slang%3D%22en-US%22%3E%3CP%3ECurrently%20spring%20cleaning%20your%20home...%20or%20trying%20to%20find%20something%20to%20do%20while%20stuck%20at%20home%3F%26nbsp%3B%20I've%20recently%20taken%20up%20the%20task%20to%20clean%20my%20NAS%20and%20other%20storage%20devices%20of%20files%20not%20touched%20in%20over%206%20months%20to%20clear%20up%20storage%20space.%26nbsp%3B%20I%20once%20again%20turn%20to%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Flearn%2Fmodules%2Fautomate-azure-tasks-with-powershell%2F%3FWT.mc_id%3DITOPSTALK-blog-abartolo%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerShell%3C%2FA%3E%3C%2FSTRONG%3E%20to%20automate%20the%20task.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELets%20begin.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20following%20script%20will%20delete%20items%20in%20my%20Downloads%20directory%20that%20are%20older%20than%206%20months%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%24Folder%20%3D%20%22G%3A%5CDownloads%22%0A%0A%23delete%20files%20older%20than%206%20months%0AGet-ChildItem%20%24Folder%20-Recurse%20-Force%20-ea%200%20%7C%0A%3F%20%7B!%24_.PsIsContainer%20-and%20%24_.LastWriteTime%20-lt%20(Get-Date).AddDays(-180)%7D%20%7C%0AForEach-Object%20%7B%0A%20%20%20%24_%20%7C%20del%20-Force%0A%20%20%20%24_.FullName%20%7C%20Out-File%20C%3A%5Clog%5Cdeletedlog.txt%20-Append%0A%7D%0A%0A%23delete%20empty%20folders%20and%20subfolders%0AGet-ChildItem%20%24Folder%20-Recurse%20-Force%20-ea%200%20%7C%0A%3F%20%7B%24_.PsIsContainer%20-eq%20%24True%7D%20%7C%0A%3F%20%7B%24_.getfiles().count%20-eq%200%7D%20%7C%0AForEach-Object%20%7B%0A%20%20%20%20%24_%20%7C%20del%20-Force%0A%20%20%20%20%24_.FullName%20%7C%20Out-File%20C%3A%5Clog%5Cdeletedlog.txt%20-Append%0A%7D%0A%3C%2FPRE%3E%0A%3CP%3EThe%20latter%20half%20of%20the%20script%20deletes%20any%20folders%20or%20subfolders%20now%20empty%20after%20the%20purge.%26nbsp%3B%20A%20deletelog.txt%20file%20is%20created%20to%20report%20on%20all%20file%20and%20folders%20that%20have%20now%20been%20removed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20always%2C%20please%20share%20below%20your%20PowerShell%20automation%20scripts%20to%20possibly%20add%20to%20or%20better%20the%20script%20shared%20above.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1255317%22%20slang%3D%22en-US%22%3E%3CP%3ECurrently%20spring%20cleaning%20your%20home...%20or%20trying%20to%20find%20something%20to%20do%20while%20stuck%20at%20home%3F%26nbsp%3B%20I've%20recently%20taken%20up%20the%20task%20to%20clean%20my%20NAS%20and%20other%20storage%20devices%20of%20files%20not%20touched%20in%20over%206%20months%20to%20clear%20up%20storage%20space.%26nbsp%3B%20I%20once%20again%20turn%20to%20PowerShell%20to%20automate%20the%20task.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22PowerShell_Basics.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F134944iD72B3B0B8F4E0886%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22PowerShell_Basics.jpg%22%20alt%3D%22PowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EPowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1255317%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAnthony%20Bartolo%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1256715%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1256715%22%20slang%3D%22en-US%22%3E%3CP%3EWell%2C%20to%20not%20arbitrarily%20delete%20root%20%2F%20OS%2Fboot%20drive%20stuff%2C%20I'd%20consider%20a%20small%20change.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24Folder%20%3D%20Read-Host%20-Prompt%20'Enter%20the%20full%20path%20to%20the%20target%20folder%20tree%20to%20delete'%0AIf%20(%24Folder%20-match%20'C%3A')%0A%7B%0A%20%20%20%20Write-Warning%20-Message%20%22You%20are%20making%20a%20distructive%20action%20on%20the%20%24Folder.%20Are%20you%20sure%20you%20want%20to%20do%20this%3F%22%0A%0A%26lt%3B%23%0A%20%20%20%20%23Delete%20files%20older%20than%206%20months%0A%20%20%20%20Get-ChildItem%20%24Folder%20-Recurse%20-Force%20-ea%200%20%7C%0A%20%20%20%20%3F%20%7B!%24_.PsIsContainer%20-and%20%24_.LastWriteTime%20-lt%20(Get-Date).AddDays(-180)%7D%20%7C%0A%20%20%20%20ForEach-Object%20%7B%0A%20%20%20%20%20%20%20%24_%20%7C%20del%20-Force%0A%20%20%20%20%20%20%20%24_.FullName%20%7C%20Out-File%20C%3A%5Clog%5Cdeletedlog.txt%20-Append%0A%20%20%20%20%7D%0A%23%26gt%3B%0A%7D%0AElse%0A%7B%0A%20%20%20%20%22Working%20on%20delete%20the%20folder%20tree%20%24Folder%22%0A%26lt%3B%23%0A%20%20%20%20%23Delete%20empty%20folders%20and%20subfolders%0A%20%20%20%20Get-ChildItem%20%24Folder%20-Recurse%20-Force%20-ea%200%20%7C%0A%20%20%20%20%3F%20%7B%24_.PsIsContainer%20-eq%20%24True%7D%20%7C%0A%20%20%20%20%3F%20%7B%24_.getfiles().count%20-eq%200%7D%20%7C%0A%20%20%20%20ForEach-Object%20%7B%0A%20%20%20%20%20%20%20%20%24_%20%7C%20del%20-Force%0A%20%20%20%20%20%20%20%20%24_.FullName%20%7C%20Out-File%20C%3A%5Clog%5Cdeletedlog.txt%20-Append%0A%20%20%20%20%7D%0A%23%26gt%3B%0A%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1257320%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1257320%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EI%20wrote%20this%20script%20for%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsietsevdschoot%2FCreateTempDrive%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECreateTempDrive%3C%2FA%3E%2C%20it%20creates%20a%20drive%20based%20on%20a%20temporary%20folder.%20All%20contents%20in%20that%20folder%20will%20be%20automatically%20removed%20after%20a%20certain%20retention%20periond.%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20scripts%20runs%20daily%20to%20clean%20a%20folder%20of%20all%20items%20which%20are%20older%20than%20the%20retention%20period.%20It%20will%20also%20delete%20any%20empty%20folders%20that%20deleting%20the%20files%20have%20caused.%20It%20supports%20an%20optional%20rundate%20and%20the%20generic%20-whatif%20and%20-confirm%20parameters.%3CBR%20%2F%3EThis%20way%20you%20can%20see%20which%20files%20and%20folders%20will%20be%20removed%20in%20a%20folder%20when%20you%20run%20the%20command%20on%20a%20certain%20date.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%5BCmdletBinding(SupportsShouldProcess)%5D%0Aparam%20(%0A%20%20%20%20%5BParameter(Mandatory)%5D%0A%20%20%20%20%5BIO.DirectoryInfo%5D%20%24path%2C%0A%20%20%20%20%5BTimeSpan%5D%20%24retentionPeriod%20%3D%20%5BTimeSpan%5D%3A%3AFromDays(14)%2C%0A%20%20%20%20%5BDateTime%5D%20%24now%20%3D%20%5BDateTime%5D%3A%3AMinValue%0A)%0A%0Aif%20(%24now%20-eq%20%5BDateTime%5D%3A%3AMinValue)%20%7B%0A%0A%20%20%20%20%24now%20%3D%20(Get-Date)%0A%7D%0A%0A%24oldFiles%20%3D%20Get-ChildItem%20%24path.FullName%20-Recurse%20-File%20%7C%20%3F%7B%20%24_.LastWriteTime%20-lt%20%24now.Subtract(%24retentionPeriod)%20%7D%0A%24folders%20%3D%20Get-ChildItem%20%24path.FullName%20-Recurse%20-Directory%20%0A%0A%24emptyFolders%20%3D%20%24folders%20%60%0A%20%20%20%20%7C%20%3F%7B%20(Get-ChildItem%20%24_.FullName%20-file%20-Recurse%20%7C%20%3F%7B%20%24_.LastWriteTime%20-gt%20%24now.Subtract(%24retentionPeriod)%20%7D)%20-eq%20%24null%20%7D%20%60%0A%20%20%20%20%7C%20Sort-Object%20-Property%20%40%7B%20Expression%3D%7B%20%24_.FullName.Split(%5BIO.Path%5D%3A%3ADirectorySeparatorChar).Count%20%7D%3B%20Descending%3D%24true%20%7D%20%20%0A%0A%24oldFiles%20%7C%20Remove-Item%20-Force%0A%24emptyFolders%20%7C%20Remove-Item%20-Force%20-Recurse%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1255857%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20to%20Delete%20Files%20Older%20Than%20X%20Days%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1255857%22%20slang%3D%22en-US%22%3E%3CP%3EI%20wrote%20a%20function%20for%20just%20this%20purpose%20a%20few%20years%20ago%2C%20also%20has%20the%20option%20to%20clean%20up%20empty%20folders.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3EFunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ERemove-AgedItems%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26lt%3B%23%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%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p%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSpecifies%26nbsp%3Bthe%26nbsp%3Btarget%26nbsp%3BAge%26nbsp%3Bin%26nbsp%3Bdays%2C%26nbsp%3Be.g.%26nbsp%3BLast%26nbsp%3Bwrite%26nbsp%3Btime%26nbsp%3Bof%26nbsp%3Bthe%26nbsp%3Bitem.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EPARAMETER%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EForce%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSwitch%26nbsp%3Bparameter%26nbsp%3Bthat%26nbsp%3Ballows%26nbsp%3Bfor%26nbsp%3Bhidden%26nbsp%3Band%26nbsp%3Bread-only%26nbsp%3Bfiles%26nbsp%3Bto%26nbsp%3Balso%26nbsp%3Bbe%26nbsp%3Bremoved.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EPARAMETER%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EEmpty%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BFolder%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BSwitch%26nbsp%3Bparameter%26nbsp%3Bto%26nbsp%3Buse%26nbsp%3Bempty%26nbsp%3Bfolder%26nbsp%3Bremove%26nbsp%3Bfunction.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EEXAMPLE%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BRemove-AgedItems%26nbsp%3B-Path%26nbsp%3B'C%3A%5CUsers%5Crholland%5CTesfFunction'%26nbsp%3B-Age%26nbsp%3B7%26nbsp%3B%23Remove%26nbsp%3BFiles%26nbsp%3BIn%26nbsp%3BThe%26nbsp%3BTarget%26nbsp%3BPath%26nbsp%3BThat%26nbsp%3BAre%26nbsp%3BOlder%26nbsp%3BThan%26nbsp%3BThe%26nbsp%3BSpecified%26nbsp%3BAge%26nbsp%3B(in%26nbsp%3Bdays)%2C%26nbsp%3BRecursively.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BRemove-AgedItems%26nbsp%3B-Path%26nbsp%3B'C%3A%5CUsers%5Crholland%5CTesfFunction'%26nbsp%3B-Age%26nbsp%3B7%26nbsp%3B-Force%26nbsp%3B%23Remove%26nbsp%3BFiles%26nbsp%3BIn%26nbsp%3BThe%26nbsp%3BTarget%26nbsp%3BPath%26nbsp%3BThat%26nbsp%3BAre%26nbsp%3BOlder%26nbsp%3BThan%26nbsp%3BThe%26nbsp%3BSpecified%26nbsp%3BAge%26nbsp%3B(in%26nbsp%3Bdays)%2C%26nbsp%3BRecursively.%26nbsp%3BForce%26nbsp%3Bwill%26nbsp%3Binclude%26nbsp%3Bhidden%26nbsp%3Band%26nbsp%3Bread-only%26nbsp%3Bfiles.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BRemove-AgedItems%26nbsp%3B-Path%26nbsp%3B'C%3A%5CUsers%5Crholland%5CTesfFunction'%26nbsp%3B-Age%26nbsp%3B0%26nbsp%3B-EmptyFolder%26nbsp%3B%23Remove%26nbsp%3BAll%26nbsp%3BEmpty%26nbsp%3BFolders%26nbsp%3BIn%26nbsp%3BTarget%26nbsp%3BPath.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BRemove-AgedItems%26nbsp%3B-Path%26nbsp%3B'C%3A%5CUsers%5Crholland%5CTesfFunction'%26nbsp%3B-Age%26nbsp%3B7%26nbsp%3B-EmptyFolder%26nbsp%3B%23Remove%26nbsp%3BAll%26nbsp%3BEmpty%26nbsp%3BFolders%26nbsp%3BIn%26nbsp%3BTarget%26nbsp%3BPath%26nbsp%3BThat%26nbsp%3BAre%26nbsp%3BOlder%26nbsp%3BThan%26nbsp%3BSpecified%26nbsp%3BAge%26nbsp%3B(in%26nbsp%3Bdays).%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E.NOTES%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BThe%26nbsp%3B-EmptyFolders%26nbsp%3Bswitch%26nbsp%3Bbranches%26nbsp%3Bthe%26nbsp%3Bfunction%26nbsp%3Bso%26nbsp%3Bthat%26nbsp%3Bit%26nbsp%3Bwill%26nbsp%3Bonly%26nbsp%3Bperform%26nbsp%3Bits%26nbsp%3Bempty%26nbsp%3Bfolder%26nbsp%3Bcleanup%26nbsp%3Boperation%2C%26nbsp%3Bit%26nbsp%3Bwill%26nbsp%3Bnot%26nbsp%3Baffect%26nbsp%3Baged%26nbsp%3Bfiles%26nbsp%3Bwith%26nbsp%3Bthis%26nbsp%3Bswitch.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BIt%26nbsp%3Bis%26nbsp%3Brecommended%26nbsp%3Bto%26nbsp%3Bfirst%26nbsp%3Bperform%26nbsp%3Ba%26nbsp%3Bcleanup%26nbsp%3Bof%26nbsp%3Bthe%26nbsp%3Baged%26nbsp%3Bfiles%26nbsp%3Bin%26nbsp%3Bthe%26nbsp%3Btarget%26nbsp%3Bpath%26nbsp%3Band%26nbsp%3Bthem%26nbsp%3Bperform%26nbsp%3Ba%26nbsp%3Bcleanup%26nbsp%3Bof%26nbsp%3Bthe%26nbsp%3Bempty%26nbsp%3Bfolders.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%23%26gt%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Eparam%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E(%5B%3C%2FSPAN%3E%3CSPAN%3EString%3C%2FSPAN%3E%3CSPAN%3E%5D%5B%3C%2FSPAN%3E%3CSPAN%3EParameter%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EMandatory%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%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3ERemove-AgedItems%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EPath%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E'%3C%2FSPAN%3E%3CSPAN%3EC%3A%5CUsers%5Crholland%5CTestFunction%3C%2FSPAN%3E%3CSPAN%3E'%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EAge%207%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3ERemove-AgedItems%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EPath%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E'%3C%2FSPAN%3E%3CSPAN%3EC%3A%5CUsers%5Crholland%5CTestFunction%3C%2FSPAN%3E%3CSPAN%3E'%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EAge%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EEmptyFolder%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Microsoft

Currently spring cleaning your home... or trying to find something to do while stuck at home?  I've recently taken up the task to clean my NAS and other storage devices of files not touched in over 6 months to clear up storage space.  I once again turn to PowerShell to automate the task.  

 

Lets begin.

 

The following script will delete items in my Downloads directory that are older than 6 months:

 

$Folder = "G:\Downloads"

#Delete files older than 6 months
Get-ChildItem $Folder -Recurse -Force -ea 0 |
? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-180)} |
ForEach-Object {
   $_ | del -Force
   $_.FullName | Out-File C:\log\deletedlog.txt -Append
}

#Delete empty folders and subfolders
Get-ChildItem $Folder -Recurse -Force -ea 0 |
? {$_.PsIsContainer -eq $True} |
? {$_.getfiles().count -eq 0} |
ForEach-Object {
    $_ | del -Force
    $_.FullName | Out-File C:\log\deletedlog.txt -Append
}

The latter half of the script deletes any folders or subfolders now empty after the purge.  A deletelog.txt file is created to report on all file and folders that have now been removed.

 

As always, please share below your PowerShell automation scripts to possibly add to or better the script shared above.

3 Comments
Occasional Visitor

I wrote a function for just this purpose a few years ago, also has the option to clean up empty folders.

 

Function Remove-AgedItems
{
    <#
    
    .DESCRIPTION
    Function that can be used to remove files older than a specified age and also remove empty folders.

    .PARAMETER Path
    Specifies the target Path.
    
    .PARAMETER Age
    Specifies the target Age in days, e.g. Last write time of the item.
    
    .PARAMETER Force
    Switch parameter that allows for hidden and read-only files to also be removed.
    
    .PARAMETER Empty Folder
    Switch parameter to use empty folder remove function.

    .EXAMPLE
    Remove-AgedItems -Path 'C:\Users\rholland\TesfFunction' -Age 7 #Remove Files In The Target Path That Are Older Than The Specified Age (in days), Recursively.

    Remove-AgedItems -Path 'C:\Users\rholland\TesfFunction' -Age 7 -Force #Remove Files In The Target Path That Are Older Than The Specified Age (in days), Recursively. Force will include hidden and read-only files.

    Remove-AgedItems -Path 'C:\Users\rholland\TesfFunction' -Age 0 -EmptyFolder #Remove All Empty Folders In Target Path.

    Remove-AgedItems -Path 'C:\Users\rholland\TesfFunction' -Age 7 -EmptyFolder #Remove All Empty Folders In Target Path That Are Older Than Specified Age (in days).

    .NOTES
    The -EmptyFolders switch branches the function so that it will only perform its empty folder cleanup operation, it will not affect aged files with this switch.
    It is recommended to first perform a cleanup of the aged files in the target path and them perform a cleanup of the empty folders.

    #>
    
    param ([String][Parameter(Mandatory = $true)]
        $Path,
        [int][Parameter(Mandatory = $true)]
        $Age,
        [switch]$Force,
        [switch]$EmptyFolder)
    
    $CurrDate = (get-date)
    
    if (Test-Path -Path $Path)
    {
        
        $Items = (Get-ChildItem -Path $Path -Recurse -Force -File)
        
        $AgedItems = ($Items | Where-object { $_.LastWriteTime -lt $CurrDate.AddDays(- $Age) })
        
        if ($EmptyFolder.IsPresent)
        {
            
            
            $Folders = @()
            ForEach ($Folder in (Get-ChildItem -Path $Path -Recurse | Where { ($_.PSisContainer) -and ($_.LastWriteTime -lt $CurrDate.AddDays(- $Age)) }))
            {
                $Folders += New-Object PSObject -Property @{
                    Object = $Folder
                    Depth = ($Folder.FullName.Split("\")).Count
                }
            }
            $Folders = $Folders | Sort Depth -Descending
            
            $Deleted = @()
            ForEach ($Folder in $Folders)
            {
                If ($Folder.Object.GetFileSystemInfos().Count -eq 0)
                {
                    
                    Remove-Item -Path $Folder.Object.FullName -Force
                    
                    Start-Sleep -Seconds 0.2
                    
                }
            }
            
        }
        
        else
        {
            
            
            if ($Force.IsPresent)
            {
                
                $AgedItems | Remove-Item -Recurse -Force
                
            }
            
            else
            {
                
                $AgedItems | Remove-Item -Recurse
            }
            
        }
        
    }
    
    Else
    {
        
        Write-Error "Target path has not been found"
        
    }
    
}

Remove-AgedItems -Path 'C:\Users\rholland\TestFunction' -Age 7

Remove-AgedItems -Path 'C:\Users\rholland\TestFunction' -Age 0 -EmptyFolder
Senior Member

Well, to not arbitrarily delete root / OS/boot drive stuff, I'd consider a small change.

 

$Folder = Read-Host -Prompt 'Enter the full path to the target folder tree to delete'
If ($Folder -match 'C:')
{
    Write-Warning -Message "You are making a distructive action on the $Folder. Are you sure you want to do this?"

<#
    #Delete files older than 6 months
    Get-ChildItem $Folder -Recurse -Force -ea 0 |
    ? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-180)} |
    ForEach-Object {
       $_ | del -Force
       $_.FullName | Out-File C:\log\deletedlog.txt -Append
    }
#>
}
Else
{
    "Working on deleting the folder tree $Folder"
<#
    #Delete empty folders and subfolders
    Get-ChildItem $Folder -Recurse -Force -ea 0 |
    ? {$_.PsIsContainer -eq $True} |
    ? {$_.getfiles().count -eq 0} |
    ForEach-Object {
        $_ | del -Force
        $_.FullName | Out-File C:\log\deletedlog.txt -Append
    }
#>
}
Occasional Visitor

 

I wrote this script for CreateTempDrive, it creates a drive based on a temporary folder. All contents in that folder will be automatically removed after a certain retention periond.      

 

This scripts runs daily to clean a folder of all items which are older than the retention period. It will also delete any empty folders that deleting the files have caused. It supports an optional rundate and the generic -whatif and -confirm parameters.
This way you can see which files and folders will be removed in a folder when you run the command on a certain date.  

 

[CmdletBinding(SupportsShouldProcess)]
param (
    [Parameter(Mandatory)]
    [IO.DirectoryInfo] $path,
    [TimeSpan] $retentionPeriod = [TimeSpan]::FromDays(14),
    [DateTime] $now = [DateTime]::MinValue
)

if ($now -eq [DateTime]::MinValue) {

    $now = (Get-Date)
}

$oldFiles = Get-ChildItem $path.FullName -Recurse -File | ?{ $_.LastWriteTime -lt $now.Subtract($retentionPeriod) }
$folders = Get-ChildItem $path.FullName -Recurse -Directory 

$emptyFolders = $folders `
    | ?{ (Get-ChildItem $_.FullName -file -Recurse | ?{ $_.LastWriteTime -gt $now.Subtract($retentionPeriod) }) -eq $null } `
    | Sort-Object -Property @{ Expression={ $_.FullName.Split([IO.Path]::DirectorySeparatorChar).Count }; Descending=$true }  

$oldFiles | Remove-Item -Force
$emptyFolders | Remove-Item -Force -Recurse