Need someone to take a second look

I have a script running that creates 24 log files per day. I am creating a script to automate archiving the 24 log files. I have hit a snag and have been staring at this problem for a few hours now. Could someone take a look and tell me what is causing the script to not find any files to archive? I have the file deletion portion commented out to ensure I can test things out repeatedly.

function Get-TimeStamp {
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}

$LogFolder = "E:\Automation\Results\Archival"
$Exists = Test-Path -Path $LogFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $LogFolder -ItemType directory
}

$logdate = (Get-Date -UFormat ".%a %m-%d-%Y %H-%M %p")
$logs = new-item -path $LogFolder -Name "Azure Agent Check Log Archival Results$logdate.log"

$Beginfolder = "E:\Automation\Results\Azure Agent"
$Start = (get-date).adddays(-1)
$End = (get-date).adddays(-1)

$Directory = Get-Item -Path "$BeginFolder"
$Folder = $Directory.Name
$DestFolder = "$Beginfolder\Archive"
$Exists = Test-Path -Path $DestFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $DestFolder -ItemType directory
}

$Files = Get-Item -path "$Beginfolder\*.*" -Exclude "Archive" | where-object{$_.CreationTime -ge $start -and $_.CreationTime -le $end}

$Filename = "$folder results logs between $Start and $End.zip"

Foreach ($File in $Files){
    Compress-Archive -path "*.*" -DestinationPath "$DestFolder\$Filename" -CompressionLevel Fastest -update
    Write-Host "$(Get-Timestamp) File $File has been added to the archive file $Filename"
    Add-Content -path $Logs -Value "$(Get-Timestamp) File $File has been added to the archive file $Filename"
    #Remove-item -path $file
}
# This will get items within a 24 hour timespan with .log extension.
Get-ChildItem -Path $Beginfolder -Filter *.log | Where-Object {
$_.CreationTime -ge (get-date).Date.AddDays(-1) -AND $_.CreationTime -le (get-date).Date
}

Just to be totally accurate - actually this will get files from exactly yesterday between 00:00 and 24:00. Depending on when the script runs that’s more than 24 hours ago. :wink:

Everything is now working the way I wanted it to. Below is the code that I now am using.

function Get-TimeStamp {
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}

$LogFolder = "E:\Automation\Results\Archival"
$Exists = Test-Path -Path $LogFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $LogFolder -ItemType directory
}

$logdate = (Get-Date -UFormat ".%a %m-%d-%Y %H-%M %p")
$logs = new-item -path $LogFolder -Name "Azure Agent Check Log Archival Results$logdate.log"

$Beginfolder = "E:\Automation\Results\Azure Agent"
$Startdate = (get-date).adddays(-1)
$Starttemp = (get-date).AddDays(-1)
$Start = (get-date $Starttemp -UFormat "%m-%d-%Y")
$Endtemp = (get-date).AddDays(-1)
$End = (get-date $endtemp -UFormat "%m-%d-%Y")

$Directory = Get-Item -Path "$BeginFolder"
$Folder = $Directory.Name
$DestFolder = "$Beginfolder\Archive"
$Exists = Test-Path -Path $DestFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $DestFolder -ItemType directory
}

$Files = Get-Item -path "$Beginfolder\*.*" -Exclude "Archive" | where-object{$_.CreationTime -ge $startdate -and $_.CreationTime -le (get-date).date}

$Filename = "$folder results logs between $Start and $End.zip"

Set-Location -path "$beginfolder"

Foreach ($File in $Files){
    Compress-Archive -path "$file" -DestinationPath "$DestFolder\$Filename" -CompressionLevel Fastest -update
    Write-Host "$(Get-Timestamp) File $File has been added to the archive file $Filename"
    Add-Content -path $Logs -Value "$(Get-Timestamp) File $File has been added to the archive file $Filename"
    Remove-item -path $file
}