I have a .tar.gz file that I need to extract. I've handled the gunzip bit with the GzipStream object from System.IO.Compression, but I couldn't find anything for dealing with tarballs in that namespace. Is there a way to deal with .tar files natively in Powershell? Note that it's only important that I be able to call any such function/method/object construction/system binary from a Powershell script; it doesn't need to actually be written in powershell. (If it matters I'm using 64-bit windows 10)

P.S. please don't say "use 7zip"; that's not native

  • Is there a reason for this necessity? I only ask because I couldn't find an answer to this too. – kayleeFrye_onDeck Aug 4 '16 at 20:33
  • Maybe, but I don't think so, and I wouldn't expect it. Gzip is used by HTTP compression, at least ASP.Net, Invoke-WebRequest, IE/Edge would need to support it, but what in the Windows ecosystem is based on 'tar'? – TessellatingHeckler Aug 5 '16 at 0:47
  • When you say native do you mean "pure" PowerShell or would you be happy to load a binary PowerShell module with a dot net class? – Glen Buktenica Aug 5 '16 at 3:02
  • 1
    You'll either have to write a tar parser in PowerShell or import a third-party library like SharpCompress or SharpZipLib – Mathias R. Jessen Aug 5 '16 at 10:12
  • 1
    @kayleeFrye_onDeck I was trying to install gnu Make and gnu FindUtils on Windows 10 computers, with the intention of replacing slow gulp tasks with fast make recipes (Windows FIND is unusable to someone used to the gnu version, hence findutils). The source for these is only available as tarballs or zips on sourceforge, but sourceforge doesn't support static file hosting, so I couldn't download from there without advanced tools like cURL (unavailable on vanilla installs of Windows). I hope that helps with whatever you needed this for. – bfieck Aug 15 '16 at 20:15

Update in 2019:

As pointed out in other answers, BSD tar was added to Windows 10 as a built-in command in 2018. This answer is still applicable if you need to support earlier versions of Windows.

I'm fairly sure that Windows 10 did not have support for extracting tar files by default prior to 2018.

1. The quick easy solution for (early versions of) Windows 10

If you can expect the script to have access to an active Internet connection, then you can simply get 7Zip support using the built-in package manager. This solution:

  • Is entirely automated via script (does not require user interaction)
  • Does not require administrator privileges
  • Only installs the 7Zip support module if it isn't already available

Here it is:

function Expand-Tar($tarFile, $dest) {

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

    Expand-7Zip $tarFile $dest

To use it:

Expand-Tar archive.tar dest

It does the job but it makes a persistent change to the client system. There is a better, but slightly more involved, solution:

2. The better solution

The better solution is to bundle 7Zip4PowerShell with your script. This solution:

  • Does not require administrative privileges
  • Does not install any software on the client system
  • Does not require internet connectivity
  • Should work on earlier versions of Windows

a. Download a copy of the 7Zip4PowerShell package

It's distributed under the LGPL-2.1 licence and so it's OK to bundle the package with your product. You should add a note to your documentation that it uses the package and provide a link since you are required to provide access to the source code for GNU licenced products.

Save-Module -Name 7Zip4Powershell -Path .

This will download it to the current directory. It's easiest to do this on Windows 10 but there are instructions on how to add PowerShell Gallery to your system on earlier versions of Windows from the link above.

b. Import the module when you need to extract the tar file

I've made a simple function just to demonstrate how you could do this based on the first solution:

function Expand-Tar($tarFile, $dest) {

    $pathToModule = ".\7Zip4Powershell\1.9.0\7Zip4PowerShell.psd1"

        Import-Module $pathToModule

    Expand-7Zip $tarFile $dest

You'll need to adjust $pathToModule to where the bundled module is actually stored when your script runs, but you should get the idea. I've written this example such that you can simply paste in both of the code blocks above into a PowerShell window and get a working Expand-Tar cmdlet:

Expand-Tar archive.tar dest
  • 1
    Nice helper! One thing to note, version 1.9.0 of 7Zip4Powershell is out. You can either change the $pathToModule or add -RequiredVersion '1.8.0' to the Save-Module command. – Aidan Ryan Feb 12 at 19:41
  • @AidanRyan Thanks - I've updated it to 1.9.0 as I can't see an easy workaround and it feels wrong to suggest earlier versions. – Don Cruickshank Feb 12 at 20:48
  • 1
    I believe an implementation for both tar and curl were added to Windows 10 around the beginning of 2018 (devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows). It works similarly to the Unix command, but I posted an answer as well. – Broper Apr 24 at 3:39
  • @Broper Thanks - I've added a note to my answer about that. – Don Cruickshank Apr 24 at 8:52

Possible workaround:

I have Windows 10 and I wanted to run curl+tar within Powershell but it lacked support. Luckily, I had Ubuntu bash on Windows 10 which comes with curl and tar preinstalled and ran it within that environment, then after download and extracting, I switched back to Powershell to continue whatever I was doing.

Or as @Don Cruickshank mentioned in comment below you can install 7zip support from within PowerShell directly with Install-Package 7Zip4Powershell. The Expand-7zip cmdlet will extract multiple archive formats, including tar.

These workarounds don't solve your particular problem, but for these that are stuck with Windows, might be useful.

  • 2
    In Windows 10, you can install 7zip support from within PowerShell directly with Install-Package 7Zip4Powershell. The Expand-7zip cmdlet will extract multiple archive formats, including tar. – Don Cruickshank Jul 30 '17 at 22:41
  • @DonCruickshank Thanks for this suggestion. – Kunok Jul 30 '17 at 22:43

I believe tar has been added as a native function in Windows 10 since the posting of this.

From the command prompt or PowerShell in Windows 10 I can run

tar -xvzf .\whatever.tar.gz

Note that the .\ was added after auto-completing by the use of tab in PowerShell, but I think it should work without that.

There may be some underlying differences between this function and its Unix implementation (since it is on Windows after all), but it worked for me.


So it's been eleven days since I asked this and the general consensus is: "No, there are no native tools in a vanilla window install that can handle tar extraction 'for you'".

This answer comes from Matthias R. Jensen and TessellatingHeckler, who both declined to answer outside of comments (I suspect due to not wanting to say "no" without an intimate knowledge of the entire Windows system architecture, which is fair).

There are certainly scripts and classes and programs you can install, but nothing "native".


Windows 10 since 2017 has tar build in so may run it as usual exe from powershell liketar -xkf $archivePath -C $outDir, or better from pwsh.


This snippet has been working for me, I don't think I have anything installed that it is using. I still have to figure out how to extract the tar that this pull out.

Function DeGZip-File{
    $outFile = $infile.Substring(0, $infile.LastIndexOfAny('.'))
    $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
    $output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
    $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)

    $buffer = New-Object byte[](1024)
        $read = $gzipstream.Read($buffer, 0, 1024)
        if ($read -le 0){break}
        $output.Write($buffer, 0, $read)



DeGZip-File $infile 
  • Thanks, but like I said I'm already at that point; I've un-gzipd it and I have a .tar – bfieck Feb 10 '17 at 23:48

This is the fragment for a PowerShell script:

    Add-Type -AssemblyName "ICSharpCode.SharpZLib"

    $file = [IO.File]::OpenRead($gzArchiveName)
    $inStream=New-Object -TypeName ICSharpCode.SharpZipLib.GZip.GZipInputStream $file
    $tarIn = New-Object -TypeName ICSharpCode.SharpZipLib.Tar.TarInputStream $inStream
    $archive = [ICSharpCode.SharpZipLib.Tar.TarArchive]::CreateInputTarArchive($tarIn)

which is equivalent to the code of TarTool.exe utility


Why really wouldn't you use 7zip?

If there is a business rule that denies such tools, trying to implement a work-around is a fool's errand. In such an environment you need to talk with stakeholders and either:

  • get a permission to use required tools
  • move the process into another a system in which tool usage is permitted
  • change the source system to send untarred files
  • explain that the requirements as such are not possible to be satisfied
  • 1
    It's not for a business, it's a personal project. There's no one telling me I can't use 7-Zip, but I can't guarantee it'll exist on users' systems and I don't want to install a program they may not want so I can use it for one command. Plus that would require admin permissions. – bfieck Aug 5 '16 at 15:30

Your Answer

