PowerShell: unzip, untar

By Xah Lee. Date: . Last updated: .

unzip

# unarchive to current dir
Expand-Archive xyz.zip

# specify a target dir
Expand-Archive -Path c:/Users/xah/xyz.zip -DestinationPath  c:/Users/xah/out/

# using literal path, no expansion
Expand-Archive -LiteralPath c:/Users/xah/xyz.zip -DestinationPath  c:/Users/xah/out/

example script:

# unzip all *nb.zip files to a dir named x
dir * -Recurse -Include "*nb.zip" | Expand-Archive -PassThru -DestinationPath x

untar, ungzip, gunzip

Windows 10 has BSD tar builtin, at C:\Windows\system32\tar.exe

# extract .tar file
tar xvf some.tar

# extract .tar.gz (.tgz) file
tar xvfz some.tar.gz

# extract .tar.bz2 file
tar xvfj some.tar.bz2

# extract .tar.xz file
tar xvfJ some.tar.xz

Decompress using 7z

You have to install 7z. ([ https://www.7-zip.org/ ])

# extract to full paths of items
7z x archiveName

Compress/Archive

Compress by zip

Compress-Archive c:/Users/xah/Pictures/ c:/Users/xah/pic.zip

Note: the max zip file Compress-Archive can create is 2 GB. As of 2021-11-07. See help Compress-Archive

Use 7z instead.

Create Tar Archive

Windows 10 has BSD tar builtin, at C:\Windows\system32\tar.exe

# create tar file
tar cvf dirname.tar dirname

tar -h for help. For more detail see Linux: Compression How-to: tar gzip bzip2 xz 7zip rar zip

Compress using 7z

7z a c:/Users/xah/Pictures.7z c:/Users/xah/Pictures/
7z a c:/Users/xah/Pictures.zip c:/Users/xah/Pictures/

PowerShell

Practical How-To

list files

list dirs

on dir

on file

Windows config

misc


PowerShell in Depth

Programing PowerShell

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples