-path vs -literalPath
compress-archive
has the two parameters -path
and -literalPath
to specifiy the files to be compressed.
They differ in that -literalPath
does not expand (or accept) wild cards characers (*
and ?
)..
Both parameters accept an
array of strings.
In order to use -literalPath
, it needs to be specified explicitly. (-path
is the default (and first) parameter for compress-archive
).
-update / -force
If the specified zip file already exists, -update
or -force
determine what happens to the zip file.
-force
will create a new zip file.
-update
adds the specified files to the zip files. If they're already in the zip file, they're updated if the zip's version of the file is older than that with which they're updated.
Example
The following command creates project.zip
that contains all view-*.sql
, table-*.sql
files that are found in the current directory, plus the readme.txt
file that also needs to be in the current directory.
Note that the first parameter by default is -path
which accepts an array of strings. So, the commas (before table-*.sql
and readme.txt
) are necessary to tell compress-archive
that they belong to this parameter.
project.zip
is not prepended by a comma, which indicates that this is the second parameter.
PS C:\> compress-archive `
view-*.sql `
, table-*.sql `
, readme.txt `
project.zip `
-force
Compress an entire folder
The following creates a zip archive for the entire folder data-2023-04
. In the zip file, data-2023-04
will be the top level folder:
PS> compress-archive data-2023-04 data-2023-04.zip
With \*
added to the folder name, the «top level» folder of the source data (data-2023-04
) does not show up in the zip file:
PS> compress-archive data-2023-04\* data-2023-04.zip