我创建了一个变量,$check
用于根据特定条件查找文件。代码如下:
$day = (get-date).day
$year = (get-date).year
$check = (Get-ChildItem |
where-object {$_.LastWriteTime.Day -eq "$day"} |
Where-Object {$_.LastWriteTime.Year -eq "$year"} |
Sort-Object LastWriteTime |
Format-Table LastWriteTime, Name, Length)
有没有办法做得更紧凑?例如使用更少的变量等。
答案1
$check=(ls|?{$_.LastWriteTime.Day -eq "$day"}|select LastWriteTime|ft LastWriteTime, Name, Length -Auto)