How to compress multiple files into one zip with PowerShell?

Question:

I want to compress multiple files into one zip.

I am stuck with this at the moment:

I get this exception

Write-Zip : Cannot bind argument to parameter ‘Path’ because it is null.

This part is the problem:

I have never used powershell before but i have to provide a script, I can’t provide a c# solution.

Answer:

The problem is that Get-ChildItem returns instances of the System.IO.FileInfo class, which doesn’t have a property named Path. Therefore the value cannot be automatically mapped to the Path parameter of the Write-Zip cmdlet through piping.

You’ll have to use the ForEach-Object cmdlet to zip the files using the System.IO.FileInfo.FullName property, which contains the full path:

Here’s a shorter version of the command using aliases and positional parameters:

Related resources:

Source:

How to compress multiple files into one zip with PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply