2 Replies Latest reply on Nov 11, 2014 2:29 PM by VMwareGuy007

    Filtering using the lowest number

    DZ1 Hot Shot



      Even though this question does not contain any directly related PowerCLI cmdlets, the overall script itself is PowerCLI. 


      I'm trying to filter a directory, but I only want to get the lowest (Minimum) number.  I had the idea in my head, and I really thought it would be easier than this.


      I changed the date on my computer, so when I ran the script it would produce a LastWriteTime that appeared to be a certain year and month, and here is what I want to do.


      I have two entries


      Mode                LastWriteTime     Length Name


           -


                     -


          -


      -


                                                                                     


      -a---         10/1/2014   7:30 PM       1555 10-1-2014 Report.csv



      -a---         10/3/2014   7:30 PM       1555 10-3-2014 Report.csv 



      What I want to do is only filter for the oldest file, the one that is 10/1/2014 



      The name of the file is generated by a date, so I need the filter to be dynamic



      Assuming I'm already in the correct directory, I tried this:



      ls | where { ($_.LastWriteTime | measure -Minimum | select -ExpandProperty Minimum) }



      What I thought should happen is that I would retrieve only 1 result and that result would be the file with a date of "10/1/2014", but both files show up, as if I ran an ls on the directory.



      To make sure I was thinking logically (or so I thought), 



      I tried this "10/1/2014", "10/10/2014", "10/26/2014" | measure -Minimum | select -ExpandProperty Minimum



      That works, only "10/1/2014" comes back, but I can't seem to get it to work when trying to filter for a certain file using ls (Get-ChildItem)