0

Running the follow command to zip all txt file:

Compress-Archive -Path "$testfolder\*.txt\" -CompressionLevel Optimal -DestinationPath $textfolder\TESTZIP

I created a scheduled task that will run every 5 minutes for a period of 1 hour. Since this is a test, files get created every 5 minutes as well. But my zip folder does not get updated.

How could I update my zip folder based on my command on top?

After 1 hour, email alerts gets sent out. I have the email settings set up.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user 9191
  • 717
  • 4
  • 11
  • 31

2 Answers2

2

When in doubt, read the documentation.

-Update

Updates the specified archive by replacing older versions of files in the archive with newer versions of files that have the same names. You can also add this parameter to add files to an existing archive.

Add the parameter -Update to your commandline.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I already did that before running a task scheduler to see if it will get updated soon – user 9191 Jun 18 '19 at 11:52
  • Compress-Archive -Path "testfolder\*.txt\* -CompressionLevel Optimal -Update -DestinationPath $textfolder\TESTZIP – user 9191 Jun 18 '19 at 11:54
  • I think it only updates if the files have the same name- my files have a "YYYYMMDDHHMMSS" on each of them, so that might be the reason why it does not update ?? – user 9191 Jun 18 '19 at 11:57
  • @user9191 No. Please read what I quoted from the documentation. Pay particular attention to the last sentence in that quote. – Ansgar Wiechers Jun 18 '19 at 12:04
  • I see that the zip file date gets modified, but the files inside does not. Ill do some research - thanks – user 9191 Jun 18 '19 at 12:38
  • Does the command itself that doesn't work correctly, or is it the scheduled task? Scheduled tasks are notoriously difficult to debug. [See here](https://stackoverflow.com/a/41635982/1630171) for some pointers. – Ansgar Wiechers Jun 18 '19 at 12:55
  • Compress-Archive -Path $testfolder\*.txt* -CompressionLevel Optimal -Update -DestinationPath $textfolder\TESTZIP – user 9191 Jun 18 '19 at 13:11
  • scheduled tasks seems to not work - just ran the command by itself and news files were added into the zip folder – user 9191 Jun 18 '19 at 13:12
  • It worked now- a simple mistake, where my powershell script was updated but my task scheduler Action file was not - thanks for your assistance. Now im trying to implement a time in my email . – user 9191 Jun 18 '19 at 13:22
0

To overwrite an existing zip file use the -Force argument.

RonnieScotland
  • 132
  • 2
  • 5