How to move a single txt file to the zip in powershell 3

Question:

I am trying to copy/move one text file to the zip. I don’t want to unzip it, copy the file and zip it back. Is there any way we can directly copy or move text file to the zip in powershell. When i am doing it in powershell, it’s doing after that when i try to look inside the zip it’s saying invalid path.

Powershell commands:

Error: The compressed folder is invalid

Answer:

>= PowerShell 5.0

Per @SonnyPuijk’s answer above, use Compress-Archive.

< PowerShell 5.0

To add a single file to an existing zip:

To create a single file zip file from scratch:

Same as above, only replace: [System.IO.Compression.ZipArchiveMode]::Update

With: [System.IO.Compression.ZipArchiveMode]::Create

Related Documentation:

Source:

How to move a single txt file to the zip in powershell 3 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply