2

I have a PowerShell script that I wrote on a Windows 10 device using PowerShell 5.1.17763.771. It takes a path to a .tgz file, unarchives it, and places the extracted folder in another path. It does this using the built-in tar cmdlet that was added to PowerShell a year or two ago. It works exactly as intended on my machine.

When running this same script on Windows Server 2016, it fails saying tar is an unrecognized cmdlet. The PowerShell version running on this server is 5.1.14393.3471. I've run every Windows update I can on the server. How can I get the native tar cmdlet to work on Windows Server 2016? Are there updates to PowerShell that I'm missing? Can I install a Microsoft-created module that includes the tar cmdlet?

Mike
  • 517
  • 2
  • 5
  • 21

2 Answers2

3

tar is an external executable, tar.exe, not a cmdlet, and while PowerShell can call it, it is unrelated to PowerShell.

On Windows 10 (since version 1803), it can be found at C:\WINDOWS\system32\tar.exe.

This blog post from 2017 announced the availability of tar.exe, alongside curl.exe in the context of containers. tar.exe is compiled from the libarchive sources (BSD-licensed); build instructions for Windows.

On Windows Server, it seems that tar.exe and curl.exe were first included with Windows Server 2019.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • Would there be any negative implications of placing `tar.exe` on Windows Server myself and using it like I would in Windows 10? Any licensing or compatibility issues? – Mike Feb 05 '20 at 20:09
  • @Mike, I would expect it to work technically (Windows Server 2016 and (at least older versions of) Windows 10 share the same kernel), and I _think_ there won't be licensing issues, but please follow the link to the license that I've just added to the answer to draw your own conclusions. – mklement0 Feb 05 '20 at 20:24
  • @Mike - Were you able to generate the tar.exe file? I used the one from Win 10 on Win 2012 r2 and it did not work. Tried the build instructions from the link mklement0 shared but was not able to get it to build without errors. – Shiva Naru Aug 31 '20 at 19:37
  • @ShivaNaru I ended up simply uploading the pre-compiled tar.exe from Windows 10 to our Windows server. Then, I would use it from PowerShell by calling the exe file directly with whatever arguments I need; for example, `C:\path\to\folder\tar.exe -xvf file.tar` – Mike Sep 02 '20 at 00:25
  • @Mike: Thank you. Does not work for me on Win 2012 r2 server. I tried what you said and I get this error in Powershell - Program 'tar.exe' failed to run: The specified executable is not a valid application for this OS platform. – Shiva Naru Sep 03 '20 at 22:45
0

Despite reports of Windows 10 having tar and curl... they don't exist on Windows 2016 Datacenter... and trying to download tar from GNU... is a compressed tar file so that doesn't help either.

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31424519) – Niklas Mohrin Apr 02 '22 at 15:46
  • Agreed, but I didn't intend to ask a new question I commented upon an existing answer to a question to say it doesn't work. – Mark Eastwood Apr 04 '22 at 13:10
  • Exactly, but you still posted your response as an answer, which is not wanted (see https://stackoverflow.com/help/deleted-answers). Once you have enough reputation, you will be able to [post comments](https://stackoverflow.com/help/privileges/comment) on existing posts :) – Niklas Mohrin Apr 04 '22 at 21:54