Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .