question

mehta.parth09 avatar image
mehta.parth09 asked

Moving file based on date difference using powershell

Hello, I would like to move 4 months older files to another location with date difference condition of current month and LastWriteTime of file. I am running below code on 2nd March 2017 and its moving Dec-16 files but only 1st and 2nd date of Dec-16 files and there are more then 10 files of Dec-16 months. Jan-17 and Feb17 files are not moving which is good. Ideally it should not move Dec-16 files too as I have written condition as $Now.AddMonths(-3). That means its checking date as well which I do not want. Code should only check month and move files accordingly. $Now = Get-Date $Lastwrite = $Now.AddMonths(-3) $childItems = Get-ChildItem $folderNameFull -Include *.txt,*.xml,*.csv,*.xls -Recurse | where {$_.LastwriteTime -lt "$Lastwrite"} Can anyone please help me with this?
powershellautomationwindows
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.