Why can’t I extract a Gzip file using PowerShell’s tar.exe?

0
0
Asked By TechTinker89 On

I'm trying to extract a Gzip file (.gz) using PowerShell's tar command but keep running into issues. I successfully extracted the contents with 7-zip, but I'd prefer to use a built-in tool since my script will be shared and not everyone has 7-zip installed. When I run the command `tar -xf c:tmptest.gz -C c:tmp`, I get the error: `tar.exe: Error opening archive: Unrecognized archive format`. Interestingly, I can extract the file with Windows File Explorer just fine. My technical background isn't strong, but I know enough to get by. I performed all tests directly in PowerShell. By the way, here's the file structure I'm working with:

* Example.gz
* ConfigData (no file extension)

3 Answers

Answered By ScriptSavant76 On

Just a note of caution: The `Expand-Archive` cmdlet can sometimes give trouble with files that have non-ASCII characters. I ran into that myself before opting to stick with 7z for reliability.

Answered By GzipGuru22 On

Just to clarify, the tar you’re using in PowerShell is actually a BSD port of tar that Microsoft included, separate from PowerShell itself. When using File Explorer, it uses native OS calls to extract files. If you want to extract Gzip files, it might be worth exploring using .NET APIs within PowerShell instead.

Answered By ScriptExplorer98 On

Have you thought of trying UNIX-style forward slashes in your path? Sometimes it works better, though I didn't have any luck with it when I tested. Worth a shot!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.