The Path
parameter accepts specific file names and file names with wildcards. So instead of C:\MyFolder
as Path
parameter you could do pass "C:\MyFolder\*
"(all its files and subdirectories hence skipping the root directory)
Compress-Archive -Path "C:\MyFolder\*" -DestinationPath "C:\MyFolder.zip"
This is also documented here,
-Path
Specifies the path or paths to the files that you want to add to the archive zipped file. To specify multiple paths, and include files
in multiple locations, use commas to separate the paths.
This parameter accepts wildcard characters. Wildcard characters allow
you to add all files in a directory to your archive file.
Using wildcards with a root directory affects the archive's contents:
To create an archive that includes the root directory, and all its
files and subdirectories, specify the root directory in the Path
without wildcards. For example: -Path C:\Reference
To create an
archive that excludes the root directory, but zips all its files and
subdirectories, use the asterisk (*) wildcard. For example: -Path C:\Reference\*
To create an archive that only zips the files in the
root directory, use the star-dot-star (*.*
) wildcard. Subdirectories
of the root aren't included in the archive. For example: -Path C:\Reference\*.*