Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I created a variable $check to find files based on certain conditions. The code looks like this:

$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)

Is there a way to do it more compactly? For example use less variables etc.

share|improve this question
    
What are the conditions you intend? What you are filtering out is all files updated on the current day of the month this year. So you'll get all files updated Feb 7th and Jan 7th 2013. Is that what you want? –  zdan Feb 7 '13 at 18:27
    
I reformatted your code so I didn't have a horizontal scroll bar. I hope that's OK with you. Also, the (parens) around the Get-ChildItem... pipeline are unnecessary. –  Jay Bazuzi Feb 7 '13 at 19:34

1 Answer 1

$check=(ls|?{$_.LastWriteTime.Day -eq "$day"}|select LastWriteTime|ft LastWriteTime, Name, Length -Auto)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.