Move or delete files older than date

Move or delete files older than date

February 26, 2022

Move Item

Get-ChildItem –Path "$sourcepath" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-90))} | Move-Item -Destination "$destinationpath"

Delete Items

Get-ChildItem –Path "$sourcepath" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item

This deletes or moves files older than 90 Days.

Change the source path and days

Leave a Comments

Your email address will not be published. Required fields are marked *

Copyright ©2023 All rights reserved