Forum Discussion

johnmsch's avatar
johnmsch
Copper Contributor
Nov 17, 2023

Compress-Archive Not Working?

I'm running Powershell version 5.1.17763.4974 on a server with Windows Server 2019 Datacenter v10.

Been using PS for years but trying Compress-Archive for the first time.

Tried building a script which didn't work.  When executing the script, it immediately goes right back to the PS prompt and nothing happens.

Trying to execute a simple command directly with something like this: 

Compress-Archive -Path 'D:\abc\*.*'  -DestinationPath 'D:\xyz\abc.zip'

Same thing happens.  Goes immediately back to the PS prompt.

I'm running PS as administrator.

What am I missing?

 

4 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    johnmsch 

     

    Hi, John.

     

    Have a look at examples four and five, as you've specified the format (i.e. *.*) that explicitly only adds files from d:\abc. Subfolders and files from those subfolders will not be added.

     

    If there's files in d:\abc then something would appear to be wrong. If there's no files but there are subfolders then what you're observing is expected behaviour, and you should change *.* simply to *, as per example four.

     

     

    Also note that Compress-Archive has limitations - when compared to the underlying .NET class upon which it's based, which I spoke to in another thread:

     

     

    Cheers,

    Lain

    • johnmsch's avatar
      johnmsch
      Copper Contributor

      Thank you LainRobertson 

      I had read through that article and completely missed the obvious answer:
      This: Compress-Archive -Path 'D:\abc\' -DestinationPath 'D:\xyz\abc.zip'
      Instead of this: Compress-Archive -Path 'D:\abc\*.*' -DestinationPath 'D:\xyz\abc.zip'

      Is working perfectly.
      In fact, the folder D:\abc is indeed empty, but there are multiple folders on the next level.

       

      If I may, I have two more questions.
      I believe I read somewhere that using this compression method is limited to 2gb file sizes?
      Is there a way to remove files from a compressed file leaving everything else in tact?

      Thanks again for your quick answer and that excellent article!

       

Resources