| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | https://github.com/santisq/PSCompression |
| schema | 2.0.0 |
Extracts selected zip archive entries to a destination directory while preserving their relative paths.
Expand-ZipEntry
-InputObject <ZipEntryBase[]>
[-Destination <String>]
[-Force]
[-PassThru]
[-Password <SecureString>]
[<CommonParameters>]The Expand-ZipEntry cmdlet extracts zip entries produced by Get-ZipEntry (or New-ZipEntry) to a destination directory. Extracted entries preserve their original relative paths and directory structure from the archive. It also supports extracting password-protected entries.
PS ..\pwsh> Get-ZipEntry path\to\myZip.zip -Include *.txt | Expand-ZipEntryThis example extracts only the .txt files from a zip archive to the current directory, preserving their relative paths within the archive.
PS ..\pwsh> Get-ZipEntry path\to\myZip.zip -Include *.txt | Expand-ZipEntry -Destination path\to\myfolderThis example extracts only the .txt files from a zip archive to the specified destination directory (created automatically if needed).
PS ..\pwsh> Get-ZipEntry path\to\myZip.zip -Exclude *.txt | Expand-ZipEntryThis example extracts everything except .txt files from a zip archive to the current directory, preserving the original structure.
Example 4: Extract all entries excluding .txt files to the current directory overwritting existing files
PS ..\pwsh> Get-ZipEntry path\to\myZip.zip -Exclude *.txt | Expand-ZipEntry -ForceThis example extracts everything except .txt files and overwrites any existing files with the same name due to the -Force switch.
Example 5: Extract all entries excluding .txt files to the current directory outputting the expanded entries
PS ..\pwsh> Get-ZipEntry path\to\myZip.zip -Exclude *.txt | Expand-ZipEntry -PassThruThis example extracts everything except .txt files and uses -PassThru to output FileInfo and DirectoryInfo objects for the extracted items. By default, the cmdlet produces no output.
PS ..\pwsh> $package = Invoke-WebRequest https://www.powershellgallery.com/api/v2/package/PSCompression
PS ..\pwsh> $file = $package | Get-ZipEntry -Include *.psd1 | Expand-ZipEntry -PassThru
PS ..\pwsh> Get-Content $file.FullName -Raw | Invoke-Expression
Name Value
---- -----
PowerShellVersion 5.1
Description Zip and GZip utilities for PowerShell!
RootModule bin/netstandard2.0/PSCompression.dll
FormatsToProcess {PSCompression.Format.ps1xml}
VariablesToExport {}
PrivateData {[PSData, System.Collections.Hashtable]}
CmdletsToExport {Get-ZipEntry, Get-ZipEntryContent, Set-ZipEntryContent, Remove-ZipEntry…}
ModuleVersion 2.0.10
Author Santiago Squarzon
CompanyName Unknown
GUID c63aa90e-ae64-4ae1-b1c8-456e0d13967e
FunctionsToExport {}
RequiredAssemblies {System.IO.Compression, System.IO.Compression.FileSystem}
Copyright (c) Santiago Squarzon. All rights reserved.
AliasesToExport {gziptofile, gzipfromfile, gziptostring, gzipfromstring…}This example downloads a NuGet package (which is a zip archive) from PowerShell Gallery, extracts the manifest (.psd1) file, and immediately evaluates it to display module metadata.
PS ..\pwsh> Get-ZipEntry .\myZip.zip -Include myEncryptedEntry.txt | Expand-ZipEntry -Password (Read-Host -AsSecureString)This example demonstrates how to expand an encrypted entry using Read-Host -AsSecureString to provide the password.
Tip
If an entry is encrypted and no password is supplied, the cmdlet will prompt for one.
Specifies the root directory where zip entries are extracted.
Note
This parameter is optional. When not used, entries are extracted relative to the current directory, preserving their paths from the archive and creating subdirectories as needed.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: $PWD
Accept pipeline input: False
Accept wildcard characters: FalseOverwrites existing files in the destination directory. Without -Force, existing files are skipped.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseOutputs System.IO.FileInfo and System.IO.DirectoryInfo objects for the extracted entries. By default, the cmdlet produces no output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the password as a SecureString to extract the encrypted zip entry.
Tip
If an entry is encrypted and no password is supplied, the cmdlet will prompt for one.
Type: SecureString
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThe zip entries to expand.
Note
- This parameter accepts pipeline input (by value). Binding by property name is also supported.
- The input are instances inheriting from
ZipEntryBase(ZipEntryFileorZipEntryDirectory) produced byGet-ZipEntryandNew-ZipEntrycmdlets.
Type: ZipEntryBase[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe instances of ZipEntryFile or ZipEntryDirectory to this cmdlet. These instances are produced by Get-ZipEntry and New-ZipEntry.
By default, this cmdlet produces no output.
When the -PassThru switch is used, the cmdlet outputs FileInfo and DirectoryInfo objects representing the extracted items.