Search code examples
windowspowershelltarwindows-server-2016libarchive

Use native tar PowerShell cmdlet on Windows Sever 2016


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?


Solution

  • 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.