【发布时间】:2018-10-11 05:35:19
【问题描述】:
我对 powershell 还很陌生,我的任务是清理存档服务器。我正在尝试创建一个脚本,通过查看它在 Powershell 中的 LastWriteTime 来将文件移动到 Year\Month 文件夹结构中。
我有以下但我不知道如何让它查看文件编辑的月份?
$Path = "D:\Data"
$NewPath = "D:\ArchiveData"
$Year = (Get-Date).Year
$Month = (Get-Date).Month
New-Item $NewPath\ -name $CurrentYear -ItemType Directory
New-Item $NewPath\$Year -Name $Month -ItemType Directory
Get-ChildItem -path $Path | Where-Object {$_.LastWriteTime -Contains (Get-Date).month} | Move-Item -Destination "$NewPath\$Year\$Month"
任何关于我如何做到这一点的想法将不胜感激?
谢谢
【问题讨论】:
标签: powershell