GetChildItem "C:\foo\bar" -Recurse -File | where { $_.Name -notmatch '[a-zA-Z_0-9^0-9]*(.pl|.xap|.go|.zip|.py|.tar|.gz|.tgz)' } | Compress-Archive -DestinationPath "C:\archive\xyz.zip"
When I execute the GetChildItem
command without output redirection, the command is returning exactly what I need. However when I redirect the output to Compress-Archive
, this cmdlet does not preserve the directory structure (all files are archived at the root) of \bar
and does not include all of the files when the GetChildItem
command is executed in isolation.
Would appreciate any input. I would typically use unix shell command(s), however I am restricted by my environment.
Update (3/4/19):
GetChildItem "C:\foo\bar" -Recurse | where { $_.Name -notmatch '[a-zA-Z_0-9^0-9]*(.pl|.xap|.go|.zip|.py|.tar|.gz|.tgz)' } | Compress-Archive -DestinationPath "C:\archive\xyz.zip"
Removing the -File switch/argument resolves the folder structure issue, but files that I want to ignore in the -notmatch
switch are no longer ignored. Given the following example:
/archive
-/a
-file.pl
-/b
-file.py
-file1.html
-index.html
-some_junk.zip
This command will produce the following output:
VERBOSE: Preparing to compress...
VERBOSE: Performing the operation "Compress-Archive" on target "
C:\archive\a
C:\archive\b".
VERBOSE: Adding 'C:\archive\a\file.pl'.
VERBOSE: Adding 'C:\archive\b\file.py'.
VERBOSE: Adding 'C:\archive\b\file1.html'.
VERBOSE: Adding 'C:\archive\index.html'.
VERBOSE: Adding 'C:\archive\some_junk.zip'.
In this case the .py, .zip, and .pl files are being included in the .zip