none
Getting Files For An Hour

    Question

  • Trying to get a list of files for the previous hour and then compress them.  For some reason, I can't narrow it down to the hour, it seems to be ignoring the end time and getting everything greater than my start time only.  What am I doing wrong here?

    $d = Get-Date
    $time = (Get-Date ($d).AddHours(-1) -UFormat %m%d%G_%H00) + ".zip"
    $start = ($d).AddMinutes(-($d).minute).AddSeconds(-($d).second).AddHours(-1)
    $end = ($d).AddMinutes(-($d).minute).AddSeconds(-($d).second).AddSeconds(-1)
    Set-Location D:\CloudFlare
    Get-ChildItem -Path D:\CloudFlare -Recurse | Where-Object {$_.LastWritetime -gt $start -and $_LastWriteTime -lt $end} | Compress-Archive -DestinationPath D:\CloudFlare\$time -Update

    This is what I get:

    PS C:\> $start,$end
    
    Wednesday, December 5, 2018 10:00:00 AM
    Wednesday, December 5, 2018 10:59:59 AM
    
    
    PS C:\> Get-ChildItem -Path D:\CloudFlare -Recurse | Where-Object {$_.LastWritetime -ge $start -and $_La
    stWriteTime -le $end}
    
    
        Directory: D:\CloudFlare
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        12/5/2018  10:00 AM       12393240 CloudFlare12052018_100000.txt
    -a----        12/5/2018  10:05 AM          88449 CloudFlare12052018_100500.txt
    -a----        12/5/2018  10:10 AM       10908919 CloudFlare12052018_101001.txt
    -a----        12/5/2018  10:15 AM       11281484 CloudFlare12052018_101500.txt
    -a----        12/5/2018  10:20 AM       10071928 CloudFlare12052018_102000.txt
    -a----        12/5/2018  10:25 AM       10015240 CloudFlare12052018_102501.txt
    -a----        12/5/2018  10:30 AM       10497547 CloudFlare12052018_103000.txt
    -a----        12/5/2018  10:35 AM        9533605 CloudFlare12052018_103500.txt
    -a----        12/5/2018  10:40 AM       12335094 CloudFlare12052018_104000.txt
    -a----        12/5/2018  10:45 AM       10985902 CloudFlare12052018_104500.txt
    -a----        12/5/2018  10:50 AM       11885017 CloudFlare12052018_105001.txt
    -a----        12/5/2018  10:55 AM       13917537 CloudFlare12052018_105500.txt
    -a----        12/5/2018  11:00 AM       10510644 CloudFlare12052018_110000.txt
    -a----        12/5/2018  11:05 AM       13288689 CloudFlare12052018_110501.txt
    -a----        12/5/2018  11:10 AM       12435296 CloudFlare12052018_111001.txt
    -a----        12/5/2018  11:15 AM       11970169 CloudFlare12052018_111500.txt
    -a----        12/5/2018  11:20 AM        9831857 CloudFlare12052018_112000.txt
    -a----        12/5/2018  11:25 AM        8588464 CloudFlare12052018_112500.txt
    -a----        12/5/2018  11:30 AM        8596632 CloudFlare12052018_113000.txt
    
    
    PS C:\>



    • Edited by WWalker0307 Wednesday, December 5, 2018 5:34 PM
    Wednesday, December 5, 2018 5:33 PM

Answers

  • Typos are a bitch...was missing a '.' for the second LastWriteTime property...
    • Marked as answer by WWalker0307 Wednesday, December 5, 2018 5:49 PM
    Wednesday, December 5, 2018 5:49 PM