| external help file | Module Name | online version | schema |
|---|---|---|---|
PSCompression.dll-Help.xml |
PSCompression |
2.0.0 |
Retrieves the content of one or more file entries from a zip archive.
Get-ZipEntryContent
-Entry <ZipEntryFile[]>
[-Encoding <Encoding>]
[-Raw]
[-Password <SecureString>]
[<CommonParameters>]Get-ZipEntryContent
-Entry <ZipEntryFile[]>
[-Raw]
[-AsByteStream]
[-BufferSize <Int32>]
[-Password <SecureString>]
[<CommonParameters>]The Get-ZipEntryContent cmdlet retrieves the content of ZipEntryFile objects produced by Get-ZipEntry or New-ZipEntry. This cmdlet supports text output (line-by-line or raw string) and binary output (byte arrays or streams). It also supports reading password-protected entries.
Tip
Entries outputted by Get-ZipEntry can be piped to this cmdlet.
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Include myrelative/entry.txt | Get-ZipEntryContentThis example retrieves the text content of a specific file entry from a zip archive. By default, content is streamed line by line (as an array of strings).
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Include myrelative/entry.txt | Get-ZipEntryContent -RawThis example retrieves the entire text content as a single multi-line string using the -Raw switch.
PS ..pwsh\> $bytes = Get-ZipEntry .\test.zip -Include test/helloworld.txt | Get-ZipEntryContent -AsByteStream
PS ..pwsh\> [System.Text.Encoding]::UTF8.GetString($bytes)
hello world!This example retrieves the raw bytes of a file entry as a byte array using -AsByteStream, then converts them to a string.
PS ..pwsh\> $bytes = Get-ZipEntry .\test.zip -Include *.md | Get-ZipEntryContent -AsByteStream -Raw
PS ..pwsh\> $bytes[0].GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Byte[] System.Array
PS ..pwsh\> $bytes[1].Length
7767This example retrieves the raw bytes of all .md files as an array of byte[] objects (one per entry) using -AsByteStream and -Raw.
PS ..\pwsh> $package = Invoke-WebRequest https://www.powershellgallery.com/api/v2/package/PSCompression
PS ..\pwsh> $package | Get-ZipEntry -Include *.psd1 | Get-ZipEntryContent -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 (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 | Get-ZipEntryContent -Password (Read-Host -AsSecureString)This example demonstrates how to read 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.
Determines the number of bytes read into the buffer before outputting the stream of bytes. This parameter applies only when -Raw is not used. The default buffer size is 128 KiB.
Type: Int32
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: 128000
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the character encoding used to read the entry content. . The default encoding is utf8NoBOM.
Note
- This parameter applies only when
-AsByteStreamis not used. - The default encoding is UTF-8 without BOM.
Type: Encoding
Parameter Sets: Stream
Aliases:
Required: False
Position: Named
Default value: utf8NoBOM
Accept pipeline input: False
Accept wildcard characters: FalseBy default, the cmdlet outputs text content as an array of strings (split on newlines). The -Raw switch returns the entire content as a single string with newlines preserved.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseThe zip entry or entries to get the content from. This parameter is designed to accept pipeline input from Get-ZipEntry but can also be used as a named parameter.
Type: ZipEntryFile[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies that the content should be read as a stream of bytes.
Type: SwitchParameter
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: False
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: FalseThis cmdlet supports the common parameters. See about_CommonParameters.
You can pipe one or more ZipEntryFile objects produced by Get-ZipEntry or New-ZipEntry to this cmdlet.
By default, this cmdlet returns the content as an array of strings, one per line. When the -Raw parameter is used, it returns a single string.
- When the
-AsByteStreamparameter is used, this cmdlet returns the content as a byte array (System.Byte[]). - When
-AsByteStreamand-Raware combined, it returns an array of byte arrays (one per entry).