en-US/PSCompression-help.xml
<?xml version="1.0" encoding="utf-8"?>
<helpItems schema="maml" xmlns="http://msh"> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"> <command:details> <command:name>Compress-ZipArchive</command:name> <command:verb>Compress</command:verb> <command:noun>ZipArchive</command:noun> <maml:description> <maml:para>The `Compress-ZipArchive` cmdlet creates a compressed, or zipped, archive file from one or more specified files or directories. It aims to overcome a few limitations of `Compress-Archive` (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-7.2)while keeping similar pipeline capabilities.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>PowerShell cmdlet that overcomes the limitation that the built-in cmdlet `Compress-Archive` has:</maml:para> <maml:para>> The `Compress-Archive` cmdlet uses the Microsoft .NET API `System.IO.Compression.ZipArchive` (https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive?view=net-6.0)to compress files. The maximum file size is 2 GB because there's a limitation of the underlying API.</maml:para> <maml:para>The easy workaround would be to use the `ZipFile.CreateFromDirectory` Method (https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.createfromdirectory?view=net-6.0#system-io-compression-zipfile-createfromdirectory(system-string-system-string)).</maml:para> <maml:para>However, there are 3 limitations while using this method:</maml:para> <maml:para> 1. The source must be a directory , a single file cannot be compressed. 2. All files (recursively) on the source folder will be compressed , we can't pick / filter files to compress. 3. It's not possible to Update the entries of an existing Zip Archive.</maml:para> <maml:para>This cmdlet should be able to handle compression same as `ZipFile.CreateFromDirectory` Method but also allow filtering files and folders to compress while keeping the file / folder structure untouched .</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>Compress-ZipArchive</maml:name> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>Specifies the path or paths to the files or directories to include in the archive file. To specify multiple paths and include files from multiple locations, use commas to separate the paths. This parameter accepts wildcard characters, allowing you to include all files in a directory or match specific patterns.</maml:para> <maml:para>> [!TIP] > 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 without wildcards. For example: `-Path C:\Reference` > - To create an archive that excludes the root directory but includes all its files and subdirectories, use the asterisk (` `) wildcard. For example: `-Path C:\Reference\ ` > - To create an archive that only includes files in the root directory (excluding subdirectories), use the star-dot-star (` . `) wildcard. For example: `-Path C:\Reference\ . `</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="DestinationPath"> <maml:name>Destination</maml:name> <maml:description> <maml:para>This parameter is required and specifies the path to the archive output file. The destination should include the name of the zipped file, and either the absolute or relative path to the zipped file.</maml:para> <maml:para>> [!NOTE] > If the file name lacks an extension, the cmdlet appends the `.zip` file name extension.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String</command:parameterValue> <dev:type> <maml:name>String</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Specifies values that indicate whether a compression operation emphasizes speed or compression size. See `CompressionLevel` Enum (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel)for details.</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" command:variableLength="false">Optimal</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">Fastest</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">NoCompression</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">SmallestSize</command:parameterValue> </command:parameterValueGroup> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="False" position="named" aliases="none"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>Specifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their `.FullName` property. Wildcard characters are supported.</maml:para> <maml:para>> [!NOTE] > Patterns are tested against the object's `.FullName` property.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Update</maml:name> <maml:description> <maml:para>Updates the specified archive by replacing older file versions in the archive with newer file versions that have the same names. You can also use this parameter to add files to an existing archive.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>Outputs the object representing the compressed file. The cmdlet produces no output by default.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Compress-ZipArchive</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="DestinationPath"> <maml:name>Destination</maml:name> <maml:description> <maml:para>This parameter is required and specifies the path to the archive output file. The destination should include the name of the zipped file, and either the absolute or relative path to the zipped file.</maml:para> <maml:para>> [!NOTE] > If the file name lacks an extension, the cmdlet appends the `.zip` file name extension.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String</command:parameterValue> <dev:type> <maml:name>String</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="PSPath"> <maml:name>LiteralPath</maml:name> <maml:description> <maml:para>Specifies the exact path or paths to the files or directories to include in the archive file. Unlike the `-Path` parameter, the value of `-LiteralPath` is used exactly as typed, with no wildcard character interpretation.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Specifies values that indicate whether a compression operation emphasizes speed or compression size. See `CompressionLevel` Enum (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel)for details.</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" command:variableLength="false">Optimal</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">Fastest</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">NoCompression</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">SmallestSize</command:parameterValue> </command:parameterValueGroup> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="False" position="named" aliases="none"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>Specifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their `.FullName` property. Wildcard characters are supported.</maml:para> <maml:para>> [!NOTE] > Patterns are tested against the object's `.FullName` property.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Update</maml:name> <maml:description> <maml:para>Updates the specified archive by replacing older file versions in the archive with newer file versions that have the same names. You can also use this parameter to add files to an existing archive.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>Outputs the object representing the compressed file. The cmdlet produces no output by default.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Compress-ZipArchive</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="DestinationPath"> <maml:name>Destination</maml:name> <maml:description> <maml:para>This parameter is required and specifies the path to the archive output file. The destination should include the name of the zipped file, and either the absolute or relative path to the zipped file.</maml:para> <maml:para>> [!NOTE] > If the file name lacks an extension, the cmdlet appends the `.zip` file name extension.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String</command:parameterValue> <dev:type> <maml:name>String</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Specifies values that indicate whether a compression operation emphasizes speed or compression size. See `CompressionLevel` Enum (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel)for details.</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" command:variableLength="false">Optimal</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">Fastest</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">NoCompression</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">SmallestSize</command:parameterValue> </command:parameterValueGroup> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="False" position="named" aliases="none"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>Specifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their `.FullName` property. Wildcard characters are supported.</maml:para> <maml:para>> [!NOTE] > Patterns are tested against the object's `.FullName` property.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Update</maml:name> <maml:description> <maml:para>Updates the specified archive by replacing older file versions in the archive with newer file versions that have the same names. You can also use this parameter to add files to an existing archive.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Force</maml:name> <maml:description> <maml:para>Overwrites the destination archive if exists otherwise it creates a new one. All existing entries are lost.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>Outputs the object representing the compressed file. The cmdlet produces no output by default.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Compress-ZipArchive</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="DestinationPath"> <maml:name>Destination</maml:name> <maml:description> <maml:para>This parameter is required and specifies the path to the archive output file. The destination should include the name of the zipped file, and either the absolute or relative path to the zipped file.</maml:para> <maml:para>> [!NOTE] > If the file name lacks an extension, the cmdlet appends the `.zip` file name extension.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String</command:parameterValue> <dev:type> <maml:name>String</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Specifies values that indicate whether a compression operation emphasizes speed or compression size. See `CompressionLevel` Enum (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel)for details.</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" command:variableLength="false">Optimal</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">Fastest</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">NoCompression</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">SmallestSize</command:parameterValue> </command:parameterValueGroup> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="False" position="named" aliases="none"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>Specifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their `.FullName` property. Wildcard characters are supported.</maml:para> <maml:para>> [!NOTE] > Patterns are tested against the object's `.FullName` property.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Update</maml:name> <maml:description> <maml:para>Updates the specified archive by replacing older file versions in the archive with newer file versions that have the same names. You can also use this parameter to add files to an existing archive.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Force</maml:name> <maml:description> <maml:para>Overwrites the destination archive if exists otherwise it creates a new one. All existing entries are lost.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>Outputs the object representing the compressed file. The cmdlet produces no output by default.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>Path</maml:name> <maml:description> <maml:para>Specifies the path or paths to the files or directories to include in the archive file. To specify multiple paths and include files from multiple locations, use commas to separate the paths. This parameter accepts wildcard characters, allowing you to include all files in a directory or match specific patterns.</maml:para> <maml:para>> [!TIP] > 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 without wildcards. For example: `-Path C:\Reference` > - To create an archive that excludes the root directory but includes all its files and subdirectories, use the asterisk (` `) wildcard. For example: `-Path C:\Reference\ ` > - To create an archive that only includes files in the root directory (excluding subdirectories), use the star-dot-star (` . `) wildcard. For example: `-Path C:\Reference\ . `</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="PSPath"> <maml:name>LiteralPath</maml:name> <maml:description> <maml:para>Specifies the exact path or paths to the files or directories to include in the archive file. Unlike the `-Path` parameter, the value of `-LiteralPath` is used exactly as typed, with no wildcard character interpretation.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="DestinationPath"> <maml:name>Destination</maml:name> <maml:description> <maml:para>This parameter is required and specifies the path to the archive output file. The destination should include the name of the zipped file, and either the absolute or relative path to the zipped file.</maml:para> <maml:para>> [!NOTE] > If the file name lacks an extension, the cmdlet appends the `.zip` file name extension.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String</command:parameterValue> <dev:type> <maml:name>String</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Specifies values that indicate whether a compression operation emphasizes speed or compression size. See `CompressionLevel` Enum (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel)for details.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="False" position="named" aliases="none"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>Specifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their `.FullName` property. Wildcard characters are supported.</maml:para> <maml:para>> [!NOTE] > Patterns are tested against the object's `.FullName` property.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Update</maml:name> <maml:description> <maml:para>Updates the specified archive by replacing older file versions in the archive with newer file versions that have the same names. You can also use this parameter to add files to an existing archive.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Force</maml:name> <maml:description> <maml:para>Overwrites the destination archive if exists otherwise it creates a new one. All existing entries are lost.</maml:para> <maml:para>> [!NOTE] > If `-Force` and `-Update` are used together this cmdlet will add or update entries.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>Outputs the object representing the compressed file. The cmdlet produces no output by default.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String[]</maml:name> </dev:type> <maml:description> <maml:para>You can pipe strings containing paths to files or directories. Output from `Get-ChildItem` or `Get-Item` can be piped to this cmdlet.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>None</maml:name> </dev:type> <maml:description> <maml:para>By default, this cmdlet produces no output.</maml:para> </maml:description> </command:returnValue> <command:returnValue> <dev:type> <maml:name>System.IO.FileInfo</maml:name> </dev:type> <maml:description> <maml:para>When the `-PassThru` switch is used this cmdlet outputs the `FileInfo` instance representing the compressed file.</maml:para> </maml:description> </command:returnValue> </command:returnValues> <maml:alertSet> <maml:alert> <maml:para>This cmdlet was initially posted to address this Stack Overflow question (https://stackoverflow.com/a/72611161/15339544). [Another question](https://stackoverflow.com/q/74129754/15339544) in the same site pointed out another limitation with the native cmdlet, it can't compress if another process has a handle on a file. To overcome this issue, and also to emulate explorer's behavior when compressing files used by another process, the cmdlet defaults to __[`FileShare 'ReadWrite, Delete'`](https://learn.microsoft.com/en-us/dotnet/api/system.io.fileshare?view=net-6.0)__ when opening a [`FileStream`](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.open?view=net-7.0).</maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>- Example 1: Compress all `.ext` files from a specific folder -</maml:title> <dev:code>Get-ChildItem .\path -Recurse -Filter *.ext | Compress-ZipArchive -Destination dest.zip</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>Example 2: Compress all `.txt` files contained in all folders in the Current Directory</maml:title> <dev:code>Compress-ZipArchive .\*\*.txt -Destination dest.zip</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>Example 3: Compress all `.ext` and `.ext2` from a specific folder</maml:title> <dev:code>Compress-ZipArchive .\*.ext, .\*.ext2 -Destination dest.zip</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>Example 4: Compress a folder using `Fastest` Compression Level</maml:title> <dev:code>Compress-ZipArchive .\path -Destination myPath.zip -CompressionLevel Fastest</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>------ Example 5: Compressing all directories in `.\Path` ------</maml:title> <dev:code>Get-ChildItem .\path -Recurse -Directory | Compress-ZipArchive -Destination dest.zip</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>--------- Example 6: Replacing an existing Zip Archive ---------</maml:title> <dev:code>Compress-ZipArchive -Path .\path -Destination dest.zip -Force</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>Example 7: Adding and updating new entries to an existing Zip Archive</maml:title> <dev:code>Get-ChildItem .\path -Recurse -Directory | Compress-ZipArchive -Destination dest.zip -Update</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>------- Example 8: Exclude files and folders from source -------</maml:title> <dev:code>Compress-ZipArchive .\path -Destination myPath.zip -Exclude *.xyz, *\test\*</dev:code> <dev:remarks> <maml:para>This example shows how to compress all items in `path` excluding all files having a `.xyz` extension and excluding a folder with name `test` and all its child items.</maml:para> <maml:para>> [!TIP] > > The `-Exclude` parameter supports wildcard patterns (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.4&viewFallbackFrom=powershell-7.3), exclusion patterns are tested against the items `.FullName` property.</maml:para> </dev:remarks> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>Online Version:</maml:linkText> <maml:uri>https://github.com/santisq/PSCompression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__System.IO.Compression__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__ZipArchive Class__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__ZipArchiveEntry Class__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry</maml:uri> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"> <command:details> <command:name>ConvertFrom-GzipString</command:name> <command:verb>ConvertFrom</command:verb> <command:noun>GzipString</command:noun> <maml:description> <maml:para>Expands Gzip Base64 compressed input strings.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>The `ConvertFrom-GzipString` cmdlet can expand Base64 encoded Gzip compressed strings using the `GzipStream` Class (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream). This cmdlet is the counterpart of [`ConvertTo-GzipString`](ConvertTo-GzipString.md).</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>ConvertFrom-GzipString</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>Specifies the input string or strings to expand.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Determines the character encoding used when expanding the input strings.</maml:para> <maml:para>> [!NOTE] > The default encoding is `utf8NoBOM` .</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> <dev:type> <maml:name>Encoding</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Utf8</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Raw</maml:name> <maml:description> <maml:para>Outputs the expanded string as a single string with newlines preserved. By default, newline characters in the expanded string are used as delimiters to separate the input into an array of strings.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Determines the character encoding used when expanding the input strings.</maml:para> <maml:para>> [!NOTE] > The default encoding is `utf8NoBOM` .</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> <dev:type> <maml:name>Encoding</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Utf8</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>Specifies the input string or strings to expand.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Raw</maml:name> <maml:description> <maml:para>Outputs the expanded string as a single string with newlines preserved. By default, newline characters in the expanded string are used as delimiters to separate the input into an array of strings.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> </dev:type> <maml:description> <maml:para>You can pipe Gzip Base64 strings to this cmdlet.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> </dev:type> <maml:description> <maml:para>By default, this cmdlet streams strings. When the `-Raw` switch is used, it returns a single multi-line string.</maml:para> </maml:description> </command:returnValue> </command:returnValues> <maml:alertSet> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>-------- Example 1: Expanding a Gzip compressed string --------</maml:title> <dev:code>PS ..\pwsh> ConvertFrom-GzipString H4sIAAAAAAAACstIzcnJ5+Uqzy/KSeHlUuTlAgBLr/K2EQAAAA== hello world !</dev:code> <dev:remarks> <maml:para></maml:para> </dev:remarks> </command:example> <command:example> <maml:title>-------- Example 2: Demonstrates how `-NoNewLine` works --------</maml:title> <dev:code>PS ..\pwsh> $strings = 'hello', 'world', '!' # New lines are preserved when the cmdlet receives an array of strings. PS ..\pwsh> $strings | ConvertTo-GzipString | ConvertFrom-GzipString hello world ! # When using the `-NoNewLine` switch, all strings are concatenated PS ..\pwsh> $strings | ConvertTo-GzipString -NoNewLine | ConvertFrom-GzipString helloworld!</dev:code> <dev:remarks> <maml:para>This example shows how the `-Raw` switch concatenates the expanded strings into a single string with newlines preserved.</maml:para> </dev:remarks> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>__ConvertTo-GzipString__</maml:linkText> <maml:uri>https://github.com/santisq/PSCompression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__System.IO.Compression__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__GzipStream Class__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream</maml:uri> </maml:navigationLink> </command:relatedLinks> </command:command> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"> <command:details> <command:name>ConvertTo-GzipString</command:name> <command:verb>ConvertTo</command:verb> <command:noun>GzipString</command:noun> <maml:description> <maml:para>Creates a Gzip Base64 compressed string from a specified input string or strings.</maml:para> </maml:description> </command:details> <maml:description> <maml:para>The `ConvertTo-GzipString` cmdlet can compress input strings into Gzip Base64 encoded strings or raw bytes using the `GzipStream` Class (https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream). For expansion of Base64 Gzip strings, see [`ConvertFrom-GzipString`](ConvertFrom-GzipString.md).</maml:para> </maml:description> <command:syntax> <command:syntaxItem> <maml:name>ConvertTo-GzipString</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>Specifies the input string or strings to compress.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="Raw"> <maml:name>AsByteStream</maml:name> <maml:description> <maml:para>Outputs the compressed byte array to the Success Stream.</maml:para> <maml:para>> [!NOTE] > This parameter is intended for use with cmdlets that accept byte arrays, such as `Out-File` and `Set-Content` with `-Encoding Byte` (Windows PowerShell 5.1) or `-AsByteStream` (PowerShell 7+).</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Define the compression level that should be used. See [`CompressionLevel` Enum](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel) for details .</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" command:variableLength="false">Optimal</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">Fastest</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">NoCompression</command:parameterValue> <command:parameterValue required="false" command:variableLength="false">SmallestSize</command:parameterValue> </command:parameterValueGroup> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Determines the character encoding used when compressing the input strings.</maml:para> <maml:para>> [!NOTE] > The default encoding is `utf8NoBOM` .</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> <dev:type> <maml:name>Encoding</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Utf8</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>NoNewLine</maml:name> <maml:description> <maml:para>The encoded string representation of the input objects are concatenated to form the output. No new line character is added after each output string when this switch is used.</maml:para> </maml:description> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:syntaxItem> </command:syntax> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="Raw"> <maml:name>AsByteStream</maml:name> <maml:description> <maml:para>Outputs the compressed byte array to the Success Stream.</maml:para> <maml:para>> [!NOTE] > This parameter is intended for use with cmdlets that accept byte arrays, such as `Out-File` and `Set-Content` with `-Encoding Byte` (Windows PowerShell 5.1) or `-AsByteStream` (PowerShell 7+).</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>CompressionLevel</maml:name> <maml:description> <maml:para>Define the compression level that should be used. See [`CompressionLevel` Enum](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.compressionlevel) for details .</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompressionLevel</command:parameterValue> <dev:type> <maml:name>CompressionLevel</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Optimal</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>Determines the character encoding used when compressing the input strings.</maml:para> <maml:para>> [!NOTE] > The default encoding is `utf8NoBOM` .</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> <dev:type> <maml:name>Encoding</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Utf8</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="none"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>Specifies the input string or strings to compress.</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">String[]</command:parameterValue> <dev:type> <maml:name>String[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>None</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <maml:name>NoNewLine</maml:name> <maml:description> <maml:para>The encoded string representation of the input objects are concatenated to form the output. No new line character is added after each output string when this switch is used.</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <command:inputTypes> <command:inputType> <dev:type> <maml:name>String</maml:name> </dev:type> <maml:description> <maml:para>You can pipe strings to this cmdlet.</maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>String</maml:name> </dev:type> <maml:description> <maml:para>By default, this cmdlet outputs a single string.</maml:para> </maml:description> </command:returnValue> <command:returnValue> <dev:type> <maml:name>Byte[]</maml:name> </dev:type> <maml:description> <maml:para>When the `-AsByteStream` switch is used this cmdlet outputs a byte array down the pipeline.</maml:para> </maml:description> </command:returnValue> </command:returnValues> <maml:alertSet> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <command:examples> <command:example> <maml:title>Example 1: Compress strings to Gzip compressed Base64 encoded string</maml:title> <dev:code>PS ..\pwsh> $strings = 'hello', 'world', '!' # With positional binding PS ..\pwsh> ConvertTo-GzipString $strings H4sIAAAAAAAEAMtIzcnJ5+Uqzy/KSeHlUuTlAgBLr/K2EQAAAA== # Or pipeline input, both work PS ..\pwsh> $strings | ConvertTo-GzipString H4sIAAAAAAAEAMtIzcnJ5+Uqzy/KSeHlUuTlAgBLr/K2EQAAAA==</dev:code> <dev:remarks> <maml:para>This example demonstrates compressing an array of strings into a single Brotli Base64 encoded string using either positional binding or pipeline input.</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---- Example 2: Create a Gzip compressed file from a string ----</maml:title> <dev:code>PS ..\pwsh> 'hello world!' | ConvertTo-GzipString -AsByteStream | Set-Content -FilePath .\helloworld.gz -AsByteStream # To read the file back you can use `ConvertFrom-BrotliString` following these steps: PS ..\pwsh> $path = Convert-Path .\helloworld.gz PS ..\pwsh> [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($path)) | ConvertFrom-GzipString hello world!</dev:code> <dev:remarks> <maml:para>Demonstrates how `-AsByteStream` outputs a byte array that can be saved to a file using `Set-Content` or `Out-File`. Note that the byte array is not enumerated.</maml:para> <maml:para>> [!NOTE] > The example uses `-AsByteStream` with `Set-Content`, which is available in PowerShell 7+. In Windows PowerShell 5.1, use `-Encoding Byte` with `Set-Content` or `Out-File` to write the byte array to a file.</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>---- Example 3: Compress strings using a specific Encoding ----</maml:title> <dev:code>PS ..\pwsh> 'ñ' | ConvertTo-GzipString -Encoding ansi | ConvertFrom-GzipString � PS ..\pwsh> 'ñ' | ConvertTo-GzipString -Encoding utf8BOM | ConvertFrom-GzipString ñ</dev:code> <dev:remarks> <maml:para>The default Encoding is `utf8NoBom`.</maml:para> </dev:remarks> </command:example> <command:example> <maml:title>Example 4: Compressing multiple files into one Gzip Base64 string</maml:title> <dev:code># Check the total length of the files PS ..\pwsh> (Get-Content myLogs\*.txt | Measure-Object Length -Sum).Sum / 1kb 87.216796875 # Check the total length after compression PS ..\pwsh> (Get-Content myLogs\*.txt | ConvertTo-GzipString).Length / 1kb 35.123456789</dev:code> <dev:remarks> <maml:para>This example demonstrates compressing the contents of multiple text files into a single Gzip Base64 string and compares the total length before and after compression.</maml:para> </dev:remarks> </command:example> </command:examples> <command:relatedLinks> <maml:navigationLink> <maml:linkText>__ConvertFrom-GzipString__</maml:linkText> <maml:uri>https://github.com/santisq/PSCompression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__System.IO.Compression__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>__GzipStream Class__</maml:linkText> <maml:uri>https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream</maml:uri> </maml:navigationLink> </command:relatedLinks> </command:command> </helpItems> |