我創建了一個變數$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)