I know a lot has been written (and asked) about zipping files with PowerShell but despite all my searches and tests I could not come up with what I need.
As per subject I'm working on a script that check a in directory for files created in a specific time range
$a= Get-ChildItem - path $logFolder |
Where-Object {$_.CreationDate -gt $startDate -and $_.CreationDate -lt $endDate}
While I can get the list of files I want/need I cannot find a way to send them to a zip file.
I've tried different appraoches like
$sourceFolder = "C:\folder1"
$destinationZip = "c:\zipped.zip"
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder, $destinationZip)
But while this works well when zipping a folder it's not what I'm looking for, sure enough I could move files to a temporary folder and zip that but looks like a waste and I'm sure there are better ways of doing this.
Keep in mind I cannot use use third party tools like 7zip etc., I cannot use PowerShell extensions nor PowerShell 5 (which would make my life all so easier).
I'm pretty sure answer is rather easy and in plain sight but my brain is in a loop and I cannot figure out how to proceed so any help would be much appreciated.