Native TAR File Extraction with PowerShell

That’s right, tar-ball 😉

On one of my projects recently, I had cause to extract a .tar.gz file during the automation process. If you are in this scenario there are potentially a couple of options around this which I’ll cover off. However, I wanted a simple, native function with no dependencies, so keep reading to see what I’ve come up with.

Potential Alternatives

Before attempting to roll my own, I did look at a couple of potential options:

Firstly, the rather excellent looking 7Zip4PowerShell module. I tested this briefly and it works well for this purpose, and does a lot more besides. I decided not to go this route as it was overkill for my scenario and introduced a dependency on another external module.

Secondly, if you have a later build of Windows 10 or Windows 2019, there is a native tar command. Also a decent option, but introduces a dependency on OS version, and I’d rather not be calling out to CLI tools if I can help it.

Some Borrowed C#

In the end, a C# snippet written by Eric Freed offered up an alternative, check it out here.

After a bit of tinkering, I was able to wrap this up into a PowerShell function which can be found here.

Usage

My personal use case was to extract a copy of VMtools direct from ESXi media. In this case, the TOOLS.T00 file at the root of the media is in fact a .tar.gz file. Let’s check out an example using this function:

Really not a lot to it but solved a big problem for me, hopefully you will find it useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: