【发布时间】:2017-03-09 09:35:10
【问题描述】:
我想将文件移动到具有当前月份日期差异条件和文件LastWriteTime 的另一个位置。
我在2nd March 2017 及其移动的Dec-16 文件上运行以下代码,但只有Dec-16 文件的第一个和第二个日期,并且Dec-16 个月的文件超过10 个。
Jan-17 和 Feb-17 文件没有移动,这很好。理想情况下,它也不应该移动 Dec-16 文件,因为我将条件写为 $Now.AddMonths(-3)。
这意味着它的检查日期也是我不想要的。代码应该只检查月份并相应地移动文件。让日期可以是任何东西,如果我在三月中旬以$Now.AddMonths(-3) 运行命令,那么文件应该移动到30th November 2016 并保持1st Dec-16 直到日期不变。
$Now = Get-Date
$Lastwrite = $Now.AddMonths(-3)
$childItems = Get-ChildItem $folderNameFull -Include .txt,.xml,.csv,.xls -Recurse | where {$_.LastwriteTime -lt "$Lastwrite"}
谁能帮我解决这个问题?
【问题讨论】:
标签: windows file powershell date automation