| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | https://github.com/santisq/PSCompression |
| schema | 2.0.0 |
Extracts selected tar archive entries to a destination directory while preserving their relative paths.
Expand-TarEntry
-InputObject <TarEntryBase[]>
[[-Destination] <String>]
[-Force]
[-PassThru]
[<CommonParameters>]The Expand-TarEntry cmdlet extracts tar entries produced by Get-TarEntry to a destination directory. Extracted entries preserve their original relative paths and directory structure from the archive. It works with both uncompressed and compressed tar archives that have been processed by Get-TarEntry.
PS C:\> Get-TarEntry .\archive.tar -Include *.txt | Expand-TarEntryThis example extracts only the .txt files from archive.tar to the current directory, preserving their relative paths within the archive.
PS C:\> Get-TarEntry .\archive.tar.gz -Include *.txt | Expand-TarEntry -Destination .\extractedThis example extracts only the .txt files from a gzip-compressed tar archive to the specified .\extracted directory (created automatically if needed).
PS C:\> Get-TarEntry .\archive.tar -Exclude *.txt | Expand-TarEntryThis example extracts everything except .txt files from archive.tar to the current directory, preserving the original structure.
PS C:\> Get-TarEntry .\archive.tar -Include *.txt | Expand-TarEntry -ForceThis example extracts the .txt files and overwrites any existing files with the same name in the destination due to the -Force switch.
PS C:\> Get-TarEntry .\archive.tar -Exclude *.txt | Expand-TarEntry -PassThru
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2025-06-23 7:00 PM folder1
-a--- 2025-06-23 7:00 PM 2048 image.pngThis 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 C:\> $stream = Invoke-WebRequest https://example.com/archive.tar.gz
PS C:\> $stream | Get-TarEntry -Include readme.md -Algorithm gz | Expand-TarEntry -PassThru | Get-ContentThis example extracts only the readme.md file from a gzip-compressed tar archive streamed from the web and immediately displays its contents.
Note
When Get-TarEntry processes a stream, it defaults to the gz (gzip) algorithm. Specify -Algorithm on Get-TarEntry if the stream uses a different compression format.
The destination directory where tar entries are extracted. If not specified, entries are extracted to their relative path in the current directory, creating any necessary subdirectories.
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: FalseThe tar entries to extract. These are instances of TarEntryBase (TarEntryFile or TarEntryDirectory) output by the Get-TarEntry cmdlet.
Note
This parameter accepts pipeline input from Get-TarEntry. Binding by name is also supported.
Type: TarEntryBase[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
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: FalseThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe instances of TarEntryFile or TarEntryDirectory from Get-TarEntry to this cmdlet.
By default, this cmdlet produces no output.
When the -PassThru switch is used, the cmdlet outputs FileInfo and DirectoryInfo objects representing the extracted items.