r/PowerShell • u/Prawn1908 • Feb 20 '26
Question Compress-Archive randomly misses files
I have a powershell script triggered by MSBuild to distribute the output binaries from a .NET app to my company's file server, but before it copies over the new files it first creates a zip file of the old files using Compress-Archive -Path (Join-Path -Path $distDir -ChildPath "*") -DestinationPath $zipPath.
However, I have always had the weird issue with this script that the resulting zip file just doesn't contain all the files for some reason. Sometimes it will get all the files, sometimes it will have only one, sometimes only two. (There are usually at least a dozen files in total.)
Anybody have a clue what may be going on?
Edit: I think I figured it out - the files not getting zipped were hidden files which are apparently ignored by Compress-Archive and there's no way to change that which is annoying. There was a different build action that hides various files which wasn't working consistently for different reasons which made pinpointing this problem even harder.
1
u/vermyx Feb 21 '26
How big are the files being compressed and what is the total size? Compress-archive uses zip16 and does not understand zip64
1
u/BlackV Feb 21 '26
maybe cause of this
why not use
does it not automatically include the the contents of the path ?
3
u/purplemonkeymad Feb 20 '26
You could try using the pipeline method as well (from the help:)
In addition the passthru parameter returns the fileinfo of the archive after it is done. I would check to see if that makes it blocking.
1
u/Future-Remote-4630 Feb 20 '26
Is there any relation between the ones that are being compressed and whether or not they are in a subdirectory?
I haven't seen compress-archive used with join path like that, I've always provided a path to the parent directory, never specified children, and I haven't encountered that issue before.
1
u/420GB Feb 21 '26
Just use
tar.exe2
u/amgtech86 Feb 20 '26
Possibly doing it a bit too fast maybe? Could use a start-sleep / wait-job or do-while maybe?