GithubHelp home page GithubHelp logo

thoemmi / 7zip4powershell Goto Github PK

View Code? Open in Web Editor NEW
377.0 19.0 64.0 11.79 MB

Powershell module for creating and extracting 7-Zip archives

License: GNU Lesser General Public License v2.1

C# 91.07% PowerShell 8.93%
powershell c-sharp cmdlet compression encryption sevenzip 7-zip

7zip4powershell's Introduction

7Zip4Powershell

Powershell module for creating and extracting 7-Zip archives supporting Powershell's WriteProgress API.

Screenshot

Note

Please note that this repository is not maintained anymore. I've created it a couple of years ago to fit my own needs (just compressing a single folder). I love that lots of other users find my package helpful.

I really appreciated if you report issues or suggest new feature. However, I don't use this package myself anymore, and I don't have the time to maintain it appropriately. So please don't expect me to fix any bugs. Any Pull Request is welcome though.

Usage

The syntax is simple as this:

Expand-7Zip
    [-ArchiveFileName] <string>
    [-TargetPath] <string>
    [-Password <string>] | [-SecurePassword <securestring>]
    [<CommonParameters>]

Compress-7Zip
    [-ArchiveFileName] <string>
    [-Path] <string>
    [[-Filter] <string>]
    [-OutputPath] <string>
    [-Format <OutputFormat> {Auto | SevenZip | Zip | GZip | BZip2 | Tar | XZ}]
    [-CompressionLevel <CompressionLevel> {None | Fast | Low | Normal | High | Ultra}]
    [-CompressionMethod <CompressionMethod> {Copy | Deflate | Deflate64 | BZip2 | Lzma | Lzma2 | Ppmd | Default}]
    [-Password <string>] | [-SecurePassword <securestring>]
    [-CustomInitialization <ScriptBlock>]
    [-TempFolder <string>]
    [-IncludeHidden]
    [-IncludeSystem
    [-EncryptFilenames]
    [-VolumeSize <int>]
    [-FlattenDirectoryStructure]
    [-SkipEmptyDirectories]
    [-PreserveDirectoryRoot]
    [-DisableRecursion]
    [-Append]
    [<CommonParameters>]

Get-7Zip
    [-ArchiveFileName] <string[]>
    [-Password <string>] | [-SecurePassword <securestring>]
    [<CommonParameters>]

Get-7ZipInformation
    [-ArchiveFileName] <string[]>
    [-Password <string>] | [-SecurePassword <securestring>]
    [<CommonParameters>]

It works with both x86 and x64 and uses SevenZipSharp as a wrapper around 7zip’s API.

Jason Fossen wrote the article PowerShell 7-Zip Module Versus Compress-Archive with Encryption where he describes some usage scenarios with 7Zip4PowerShell.

Where to get it

7Zip4Powershell is published at PowerShell Gallery.

https://www.powershellgallery.com/packages/7Zip4Powershell

Customization

Compress-7Zip accepts a script block for customization. The script block gets passed the current SevenZipCompressor instance. E.g. you can set the multithread mode this way:

$initScript = {
    param ($compressor)
    $compressor.CustomParameters.Add("mt", "off")
}

Compress-7Zip -Path . -ArchiveFileName demo.7z -CustomInitialization $initScript

A list of all custom parameters can be found here.

Changelog

  • Updates 7-Zip libraries to 22.01 and NuGet packages (contributed by @kborowinski in #84)
  • Adds TempFolder parameter to Compress-7Zip (requested in #78)
  • Now based on .NET Standard 2.0 (thanks to @kborowinski for testing)
  • Uses PowerShell 5 reference assembly, which reduces the package size dramatically (#61, contributed by @kborowinski)
  • Replaces SevenZipSharp.Net45 with Squid-Box.SevenZipSharp library and adds new parameter PreserveDirectoryRoot for Compress-7zip. (#57, contributed by @kborowinski)
  • Adds new parameter OutputPath for Compress-7Zip (#60, contributed by @iRebbok)
  • Updated 7-Zip dlls to 16.04
  • Disabled the CustomInitialization parameter for Expand-7Zip, will be removed in future versions.

January 25, 2017

  • Added optional SecurePassword parameter of type SecureString to all cmdlets. (#34, #36)

October 27, 2016

  • Compression with password encryption could cause an exception (#33)

October 16, 2016

  • If Format is not specified, it is inferred from the file extension of ArchiveFileName (#24, proposed by @onyxhat)
  • Added new parameter VolumeSize to specify the colume size for Compress-7Zip (#25, proposed by @rgel)
  • Added new switches FlattenDirectoryStructure, SkipEmptyDirectories, and DisableRecursion to Compress-7Zip (#27, contributed by @itmagination)
  • Added new switch Append to Compress-7Zip to append files to an existing archive (#30, inspired by @itmagination)

June 15, 2016

  • added Get-7ZipInformation cmdlet
  • use default compression method in Compress-7Zip (previously it was PPMd, for whatever reason) (#11)
  • allow piped input for Get-7Zip (#15)
  • use WriteDebug instead of Write of logging (#13)

June 5, 2016

  • Added parameter -EncryptFilenames to Compress-7Zip (#10, requested by @JasonFossen)

May 29, 2016

  • Added Get-7Zip to get a list of files in an archive (#9, contributed by @gigi81)

30 March, 2016

  • Added Password parameter to both Compress-7Zip and Expand-7Zip (#8)

Motivation

I've written and maintaining the module just for fun and to serve my own needs. If it's useful for you too, that's great. I don't demand anything in return.

However, if you like this module and feel the urge to give something back, a coffee or a beer is always appreciated. Thank you very much in advance.

PayPal.me

7zip4powershell's People

Contributors

cptmikhailov avatar csharper2010 avatar gigi81 avatar irebbok avatar kborowinski avatar mattiasmaahl avatar mike-crowley avatar thoemmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

7zip4powershell's Issues

Support for progress event hooks

The current implementation is great if there is a human looking at the console. If these cmdlets are wrapped in a script, and there was a need make decisions about the progress being made (such as logging or timeout), that's not currently possible.

It doesn’t work at win11 22H2,but work at 21H2 bug

Dear Developer:
我写了一个powershell文件,目的是让powershell自动压缩当前目录内的文件夹和其中的文件,压缩包为该文件夹名称,但是遇到了bug,在此前win11 21H2系统内,可以正常运行该powershell文件。但是我升级了win11 22H2后,运行会出现错误。
powershell文件内容如下:

$x= Split-Path -Parent $MyInvocation.MyCommand.Definition # get the path
$fileList= Get-ChildItem $x -Directory
foreach($file in $filelist){ # enum the files list
	if(($file.name -ne 'move.ps1')){ 
		echo $file.name #print the file name
        Set-Location 
        #$y=split-path -parent $MyInvocation.MyCommand.Definition
        Compress-7Zip -path $file -ArchiveFileName "$($file.name).7z" -Format SevenZip
        Set-Location $x
	}
}
pause

报错的信息如下:

{F066D14D-4796-4750-8D59-99C6FB6AB26D}
Compress-7Zip : 找不到与参数名称“path”匹配的参数。
所在位置 E:\图片\Feedback\move.ps1:8 字符: 23
+         Compress-7Zip -path $file -ArchiveFileName "$($file.name).7z" ...
+                       ~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Compress-7Zip],ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Compress-7Zip

按 Enter 键继续...:

系统版本信息:

Get-CimInstance -ClassName Win32_OperatingSystem |
>>   Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion


BuildNumber             : 22621
BuildType               : Multiprocessor Free
OSType                  : 18
ServicePackMajorVersion : 0
ServicePackMinorVersion : 0

powershell版本信息:

PS C:\Users\i_am_> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Waiting for you reply.Thank you.
soooooooo
2023/4/4

Multiple Directories

Is it possible to Compress-7zip multiple directories within a directory? I can't find anything about it in the documentation.

PowerShell Core Support

Would you consider adding support for PowerShell core support so this module will work on macOS and Linux?

Not working on Nanoserver

Hi, when I install this module from PSGallery I get the following error when using it.

Get-7Zip : Could not load type 'System.MarshalByRefObject' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
At line:1 char:1
+ Get-7Zip .\Miniconda3\preconda.tar.bz2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-7Zip], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,SevenZip4PowerShell.Get7Zip
Expand-7Zip : Could not load type 'System.MarshalByRefObject' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
At line:1 char:1
+ Expand-7Zip -ArchiveFileName .\Miniconda3\preconda.tar.bz2 -TargetPat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Expand-7Zip], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,SevenZip4PowerShell.Expand7Zip

To check if a compressed file is encripted

I think is very interesting, if you are decompressing a lot of files, to know if a file is password protected to eventually ignore it.
Is posible to do with this code
& $7z l -slt -- $compress_file) | select-string -pattern "Encrypted = +"
But i prefeer doing it with "get-7zipinformation.encripted" for example.

Expand-7Zip creates zero-length file when password is missing or incorrect

Hello:

When a 7z archive is encrypted with a password, but the -EncryptFileNames switch is not used, then a zero-length file is created when expanding with either no password or the wrong password. The name of the file created (with zero bytes in it) is taken from the 7z archive.

For example, if a file named FOO.TXT has 1KB of text in it, then it is successfully encrypted like this (notice, no -EncryptFileNames switch):

Compress-7Zip -Path .\FOO.TXT -ArchiveFileName .\PlainFileNames.7z -Format SevenZip -Password "DasP@sswurd"

The the following command fails to extract the contents of FOO.TXT as expected:

Expand-7Zip -ArchiveFileName .\PlainFileNames.7z -TargetPath . -Password "WrongPassword"

But the above command does create a file named FOO.TXT that has zero bytes inside of it. This also happens when no -Password is given at all.

Even worse, if FOO.TXT already exists in the target path with contents, that existing file will be overwritten by the zero-length file.

This is unexpected and dangerous. When attempting to expand files from an encrypted archive and the decryption fails, then 1) no files should be created and 2) no existing files should be overwritten.

Note that when the encrypted archive is originally created with the -EncryptFileNames switch, and the expansion later fails because of an incorrect password, then no existing files are overwritten and no zero-length files are created. This should always be the behavior when decryption fails.

Cheers,
   J.

Get-7Zip should accept piped input

Suggestion:

Get-7Zip should be able to accept piped file input, for example:

  dir *.zip,*.7z | Get-7Zip

It might not be possible, but it would be nice if the output included the format, compression method, compression level, and other details too (the underlying library might not expose that).

Thanks!

Nothing happens when trying to compress, no error, nothing

I have a very weird error for some reason because I have been using that module for quite a while

I have a very big folder to compress and nothing happen anymore and I am not sure why

PS C:\Users\LeChat\Desktop> Get-Date

Sunday, September 25, 2022 17:41:34


PS C:\Users\LeChat\Desktop> "{0:N2} GB" -f ((gci big-folder -Recurse | measure Length -s).sum / 1Gb)
9.08 GB
PS C:\Users\LeChat\Desktop> Compress-7Zip -Path .\big-folder\ -ArchiveFileName test.7z
PS C:\Users\LeChat\Desktop> Get-Date

Sunday, September 25, 2022 17:41:56

very weird

Invalid archive `tar`

I'm using a PowerShell script to download and extract an archive. It's a .tar.bz2 and when I use Expand-7Zip for the first time, it only decompresses it, leaving a .tar file. But when I try to extract it, I get an error message saying it's an invalid package. That is weird because when I double-click on it, 7Zip GUI opens it normally 🤔. This is the whole script:

$ErrorActionPreference = "Stop"

function Expand-Tar($TarFile, $Destination) {

    if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) {
        Install-Package -Scope CurrentUser -Force 7Zip4PowerShell > $null
    }

    Expand-7Zip $TarFile $Destination
}

Write-Output "Downloading libraries..."

Invoke-WebRequest http://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 -OutFile libs.tar.bz2
New-Item -ItemType directory -Name libs

Write-Output "Exctracting..."

Expand-Tar -TarFile libs.tar.bz2
Expand-Tar -TarFile libs.tar -Destination libs
Remove-Item libs.tar.bz2
Write-Output "Libs have been extracted to the libs/ directory. Copy files for your platform to the debug folder."

And this is the error:

Expand-7Zip : Invalid archive: open/read error! Is it encrypted and a wrong password was provided?
If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake.
At C:\Users\Michal Grňo\Documents\GitHub\mff-totem\getlibs.ps1:14 char:5
+     Expand-7Zip $TarFile $Destination
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (SevenZip4PowerS...ip+ExpandWorker:ExpandWorker) [Expand-7Zip], SevenZipArchiveException
    + FullyQualifiedErrorId : err01,SevenZip4PowerShell.Expand7Zip

As I said, extracting with GUI (v18.01) works fine...

The execution has failed due to the bug in the SevenZipSharp

Hello,

I have a batch file that issues ssh and scp commands (after installing OpenSSH) to tar/compress a directory on the Linux machine then copied to the Windows 10 machine. I have these parts working. I found this module may be imported and used to decompress the tar. When the script executes the following is seen on the console:

Expand-7Zip : The execution has failed due to the bug in the SevenZipSharp.
Please report about it to http://sevenzipsharp.codeplex.com/WorkItem/List.aspx, post the release number and attach the archive.
At line:1 char:1
+ Expand-7Zip -ArchiveFileName repo_2018-12-21_1614.tar.gz -Targ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (SevenZip4PowerS...ip+ExpandWorker:ExpandWorker) [Expand-7Zip], SevenZipException
    + FullyQualifiedErrorId : err01,SevenZip4PowerShell.Expand7Zip

I am able to view the tar file using WinRAR, so I believe the file is not corrupt. Any idea what I am doing wrong?

Thanks,
Mark

Update-Help fails

I have installed 1.8.0. Is there anything I need to do?

PS C:\WINDOWS\system32> Update-Help
Update-Help : Failed to update Help for the module(s) '7Zip4Powershell' with UI culture(s) {en-US} : The value of the
HelpInfoUri key in the module manifest must resolve to a container or root URL on a website where the help files are stored. The
HelpInfoUri 'https://github.com/thoemmi/7Zip4Powershell' does not resolve to a container.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : InvalidHelpInfoUri,Microsoft.PowerShell.Commands.UpdateHelpCommand

custom Parameter dosn't work on Expand-7Zip

Using the following create an Error.

$initScript = {  
    param ($extractor)  
    #$extractor.CustomParameters.Add("mt","off")  
    #$extractor.CustomParameters.Add("xr","!*.txt")  
    $extractor.CustomParameters.Add("x","r!*.txt")  
}  
$Ext72=Expand-7Zip -ArchiveFileName $ArchiveFileName.FullName -TargetPath $output2Dir -CustomInitialization $initScript -Debug -Verbose  

Expand-7Zip : Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In c:\temp\Extract.ps1:xx Zeichen:yy

  • ... $Ext72=Expand-7Zip -ArchiveFileName $ArchiveFileName.FullName -T ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    
    • CategoryInfo : NotSpecified: (SevenZip4PowerS...ip+ExpandWorker:ExpandWorker) [Expand-7Zip], RuntimeException
    • FullyQualifiedErrorId : err01,SevenZip4PowerShell.Expand7Zip

I have to check the Sourcecode for the right Parameter because compressor from example dosn't work.
I tried to do something like this:
7z.exe x Demo.7z -xr!*txt -oDemo2
and exclude all *.txt files from Archive.

WriteVerbose() instead of Write()

Suggestion:

  1. Replace all the Write() with WriteVerbose() in the cmdlets, so that this ongoing status information is only displayed when using the -Verbose switch. These verbose messages could optionally include more low-level information too, like compression method used, time transpired for each file, full path, etc. The progress bar already gives a visual hint that work is being done in the background.

  2. The compress/expand cmdlets should output nothing to the pipeline (just throw exceptions), just like Microsoft's Compress/Expand-Archive cmdlets.

Unable to specify AES-256 as an encryption method

When using Compress-7zip to create an encrypted archive, there's no way to specify AES-256 when creating *.zip archives. The module automatically defaults to ZipCrypto which has proven to be a weak cipher.

Archive Password Support?

Never mind - was able to add this for my fork - consider it closed

Do you have plans to add password support for archives, or is there any way to do this via the CustomInitialization script?

Cannot create archive from empty directory

Creating an archive from an empty directory results in the error message Compress-7Zip : Invalid file names have been specified: Message: the specified directory is empty! and a zero byte (invalid) 7z file. Empty directories should not be a special case.

Does not work in Powershell on Linux

Compress-7Zip: Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory

This is with p7zip installed on Linux as well. I am not sure if there is a way to fix this problem, but it is inconvenient since it broke my script once I moved it to Linux.

Handling of long paths

I'm getting this error with one of the files I'm extracting:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I had expected this would behave like 7zip but it:

  • is significantly slower on large files: 6:13 vs 1:47 on file I was testing
  • doesn't handle long paths.

I'm running a script in Powershell 4 and using vs 1.8.0 of the module.

Security Vulnerabilities with 7Zip DLLs

Looking at the 7Zip4Powershell repo indicates that the included 7Zip DLLs are about 5 years old. Since then there have been many security vulnerabilities identified with 7Zip. Can the 7Zip DLLs included in this project be updated to their latest available versions?

Implement a -WhatIf switch

Suggestion:

Implement a -WhatIf switch that outputs the same info as when using -Verbose (using mostly the same code hopefully), but not actually do anything of course.

This would be useful for testing a command that would overwrite existing files or that would take many minutes/hours to complete.

Parameter -VolumeSize only Int32

I like this Powershell-module and I use it very often.

Is there an chance to extend the parameter -VolumeSize to Int64 (to compress bigger archives)?

Thankx
AndyGss

When using volumesize archive files aren't created

Hi,

I'm trying to use the module. Everything works great, except when i try to use -VolumeSize with what ever parameter (from 1 to 10000) is just doesn't create the archives. It says it does, but when i check nothing is made. Even tried it with verbose on, and the message "VERBOSE: Compression finished" shows, but no archives.

When i don't give the parameter volumesize i get:
VERBOSE: 1 files found for compression
VERBOSE: Compressing Archive.7z
VERBOSE: Compression finished

With the parameter volumesize i only get:
VERBOSE: Compression finished

Am i overlooking something?

Compression Format 7zip Unless Explicitly Defined When Extension Provided for Archive

I noticed that the archives always seemed to be using the 7z packaging regardless of what I specified saving the archive as (e.g. .zip, .bzip, .tar, etc.). I implemented a basic switch that correctly infers the archive format based on the archive extension - the ArchiveFormat flag can still be used as an override, but otherwise seems unnecessary and this reduced instances where the flag isn't passed and other extraction utilities think they have a .tar.gz but are in fact needing to decompress a 7z archive which they may be unable to handle correctly.

Quick and dirty implementation, but worked in my fork;

                switch (System.IO.Path.GetExtension(archiveFileName).ToLowerInvariant()) {
                    case ".7z":
                        _cmdlet.Format = OutArchiveFormat.SevenZip;
                        break;
                    case ".zip":
                        _cmdlet.Format = OutArchiveFormat.Zip;
                        break;
                    case ".gz":
                        _cmdlet.Format = OutArchiveFormat.GZip;
                        break;
                    case ".bz2":
                        _cmdlet.Format = OutArchiveFormat.BZip2;
                        break;
                    case ".tar":
                        _cmdlet.Format = OutArchiveFormat.Tar;
                        break;
                    case ".xz":
                        _cmdlet.Format = OutArchiveFormat.XZ;
                        break;
                }

Module not respecting temp/working directory settings

The module is using %temp% directory for working space regardless of what is set in the 7zip program, and has no way to specify on the command line that i can find. It is not an option that is part of the custom initialization script from what i can tell either. This is causing large archive operations to fill c: drives on systems when there is ample space on the drive the archive is being placed.

Filter on directory names and recursion

Trying to recursively pack a selection of files and directories. The resulting zip file is does not have the contents I would expect.

2016-08-08 08_32_54-windows powershell

The item on the left was created in windows explorer using the 7zip gui.

Note that the item on the right has all of the folders in the source path. This can be seen by 2 points, the folder count is 835, and the "Testing" string lists folder 1305584 which should not be present.

I am assuming that recursion did not occur because even though there were more input objects to the item on the right, the archive size is smaller.

2016-08-08 08_33_19-windows powershell

I might be able to look at this later, but wanted to get you the example in case I am misunderstanding something or it is a trivial fix.

Access to path is denied

I'm trying to compress multiple folders into separate zip files however I keep getting "Access to path is denied". if I run 7za.exe by itself it can zip the folders just fine.

My Script:

$folders = Get-ChildItem -Exclude ".mig",".zip","_Easy File Transfer (migwiz)"
$env:Path = $env:Path + ";K:\TechStuff\Tech_Software\7za"

foreach($folder in $folders) {

Compress-7Zip -Path $folder.Name -Format Zip -CompressionLevel None -ArchiveFileName ($folder.Name + ".zip")

}

Error:

Compress-7Zip : Access to the path 'K:\Profile Backups\spatrico' is denied.
At line:6 char:5

  • Compress-7Zip -Path $folder.Name -Format Zip -CompressionLevel No ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (SevenZip4PowerS...+CompressWorker:CompressWorker) [Compress-7Zip], UnauthorizedAccessException
    • FullyQualifiedErrorId : err01,SevenZip4PowerShell.Compress7Zip

Encrypted archives should not reveal file names

Most importantly, Thank You for writing this and making it available on the PSGallery!

Request: please do not show the names of files in archives that have been encrypted with a password. The default should be to encrypt the file names too, not just the file contents.

If this is not practical for some reason, then please add a switch to encrypt file names. The inability to encrypt file names is kind of a deal-killer.

Support compressing files

Support compressing several files and/or directories into a single archive instead of forcing one whole directory.
Automatically find a good base path so the relative paths in the archive are sound.

Exclusions list?

Hi, I could not find a way to exclude specific paths, the -Filter parameter is inclusive, not exclusive. Is there an approach for doing it?

Thanks

.app archive not expanding with powershell module but with 7z.exe

I am currently trying to automate some stuff regarding our app packages with are compressed into an exotic archive with the extension .app

When I'm using the 7Zip GUI I can just open and/or extract the archive to get at the files inside. But when I'm trying to use the powershell module I get the following error when I try to expand-7z the .app file:

Expand-7Zip : Extension "app" is not a supported archive file name extension.

I already found a "workaround" if I just use the command-line functionality for the 7z.exe (& 'C:\Program Files\7-Zip\7z.exe' x '.\our_app_3.0.7.0.app' -o*) but that would require me to make sure that I install the necessary Program on our build slaves and I would much rather just stay with using only powershell modules.

I was wondering if there is any way I could make the ps module behave like the exe or if it is something that the dll is not able to do?

Any answer would be greatly appreciated :)

Extending support to Powershell Core 6 and Powershell 7 on Windows

Migrating the app to use .NET Standard 2.0 will allow this module to be used with the newest versions of Powershell. It won't allow cross-platform compatibility due to the issue with SevenZipSharp. I have created a pull request that accomplishes this and have tested it with Windows Powershell 5.1 and Powershell 7.

Feature request

Is it possible to add -Split parameter to split archives into fixed size peaces.
Like -v700m in the command line utility 7za.exe.
Example: 7za.exe a .\arch.zip .\file.iso -v700m.
Thanks

ErrorAction Parameter for Get-7Zip and Get-7ZipInformation

Hello:

When attempting to open an encrypted archive with the wrong password, an exception is correctly thrown, but the -ErrorAction parameter appears to not be respected. For example:

Get-7Zip -ArchiveFileName .\Encrypted.7z -Password "WrongPassword" -ErrorAction SilentlyContinue

Is not silent. And "-ErrorAction Stop" does not stop.

Both Get-7Zip and Get-7ZipInformation appear to not respect -ErrorAction, but Expand-7Zip does (haven't tried the other cmdlets).

Thanks for the module!
Cheers,
J.

Only extrac some files in the 7z package

Hi, there,Can I only get some files in the 7z pakage
Here is my 7z pakage:
C:\test.7z
C:\test.7z\c.docx
C:\test.7z\666\666.jpg
C:\test.7z\666\current.docx

Now, I only want to extrat 666.jpg

Compress files based on LastWriteTime

Hello,

This module is working great for me. I am looking to expand how I use it by only adding files to an archive that have been modified in the last day. When I try using the below code, no .7z file is created. Is there some way to accomplish this?

$lastWrite = (Get-Date).AddDays(-1)
Get-ChildItem C:\Temp | Where {$_.LastWriteTime -ge "$LastWrite"} |
Compress-7Zip -Format SevenZip -ArchiveFileName "C:\Backup\test.7z" -Password "Password"

Thank you,
Eric

Increase memory used for compression

Thank you for this module!
I am trying to incorporate this script into a database backup script. Since I have 40GB worth of SQL .bak files to be zipped an compressed - I am wondering how to give it more resources?
Could you please exemplify how to give more memory to it? It now uses only 300Mb for the compression.

Deflate and Deflate64 appear to still be using LZMA and cannot be opened by Windows File Explorer

With 7Zip4PowerShell 1.5.0, when I run the following commands in PoSh 5.0 on Windows 10:

Compress-7Zip -Path F:\folder -ArchiveFileName archive1.zip -CompressionMethod Deflate

Compress-7Zip -Path F:\folder -ArchiveFileName archive64.zip -CompressionMethod Deflate64

The two zip files are created successfully and Z-Zip can open them, but Windows File Explorer cannot open them. The error message is "Windows cannot open the folder. The Compressed (zipped) Folder '...' is invalid." The built-in PowerShell Expand-Archive cmdlet cannot open them either.

When these archives are opened in 7-Zip, the compression method shown is "LZMA:16", not "Deflate" or "Deflate64". When I open zips created by File Explorer in 7-Zip, the compression method is "Deflate".

Other compression methods tested (BZip2, Ppmd, Lzma, Lzma2) create archives of the expected types when using "Compress-7Zip -CompressionMethod xxxx". The "Default" method uses LZMA:16.

Note that when "-Format Zip" is used, then it defaults to Deflate as expected, and Deflate64 can also optionally be set as the compression method, and both such zip-format files can be opened in File Explorer without problems.

So, when -CompressionMethod is either Deflate or Deflate64, and -Format is not specified, should -Format default to Zip? Should the other -CompressionMethod options also have associated -Format defaults when -Format is not explicitly given in order to avoid compatibility problems or error messages when sharing archives with people who are not using 7-Zip?

Append not possible with EncryptFilenames

Firstly, thank you for sharing this script. That's really kind of you!

I have noticed that when using -Format SevenZip -EncryptfileNames, then appending a file to an existing .7z archive gives an error message:

Compress-7Zip : Invalid archive: open/read error! Is it encrypted and a wrong password was provided?
If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake. Message: Can not update the archive: Open() failed.
At line:1 char:1
+ Compress-7Zip -ArchiveFileName test2.7z -Path .\zip.txt -Format Seven ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (SevenZip4PowerS...+CompressWorker:CompressWorker) [Compress-7Zip], SevenZipArchiveException
    + FullyQualifiedErrorId : err01,SevenZip4PowerShell.Compress7Zip

The -Append function seems to work perfectly when the filenames are not encrypted.

Is this something you might be able to have a look at, at some time please.

Kind regards,
Tomas

Add support for CustomParameters (SevenZipSharp)

the custom parameters dictionary property of SevenZipCompressor I believe is how you can pass in switches:

http://sevenzip.sourceforge.jp/chm/cmdline/switches/method.htm

I think the most important one is

mt=[off | on | {N}]
Sets multithread mode. If you have a multiprocessor or multicore system, you can get a speed increase with this switch. This option affects only compression (with any method) and decompression of BZip2 streams. Each thread in the multithread mode uses 32 MB of RAM for buffering. If you specify {N}, 7-Zip tries to use N threads.

Compress-7Zip : Index was outside the bounds of the array.

Having an issues with Windows Server 2012 R2 and Compress-7Zip. Code looks like this:
$AbsoluteSourcePath = C:\Path\To\Folder
$AbsoluteDestPath = C:\Path\To\Filename.zip
Compress-7Zip -Path $AbsoluteSourcePath -ArchiveFileName $AbsoluteDestPath -Format Zip -Password "password"

The exceptions that gets thrown is:
Compress-7Zip : Index was outside the bounds of the array.
At C:\STSCO\Scripts\archiveDataForSTSCO.ps1:21 char:5

  • Compress-7Zip -Path $AbsoluteSourcePath -ArchiveFileName $Absolut ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (SevenZip4PowerS...+CompressWorker:CompressWorker) [Compress-7Zip], IndexOutOfRangeE
      xception
    • FullyQualifiedErrorId : err01,SevenZip4PowerShell.Compress7Zip

I can't seem to figure out why this is occurring as the same script runs fine on my Windows 10 Anniversary Edition unit. Any information would be helpful.
Thank you.

Can't use PowerShell encrypted passwords

At the moment we have a CSV file that contains various parameters for zipping and encrypting files, this file of course contains the encryption password.

We encrypt these passwords with PowerShell and then the script reads the passwords in when required.

7Zip4Powershell isn't currently able (from what I can tell) to decrypt PowerShell encrypted passwords securely, so we end up having to do something like this...

[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR(($password | ConvertTo-SecureString))))

The above will decrypt the encrypted password before it's parsed in, however this is insecure as the password is then in plain text so we would prefer to use a secure method like...

$credential = New-Object System.Management.Automation.PSCredential $acquser,(Get-Content $password | ConvertTo-SecureString)

It would be great if 7Zip4Powershell was capable of this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.