Unzip via PowerShell

Just a short tip here, on using built-in PowerShell functionality to extract a zipped file.

waithidden cmd.exe /c ""powershell.exe" -ExecutionPolicy Bypass -NonInteractive -C Expand-Archive -Path '{pathname of download folder}\My_Zipped_File.zip' -DestinationPath '{pathname of download folder}\My_Extraction_Folder' -Force -Verbose:$true > extraction_log.txt 2>&1"

This extracts the zip file to a new directory “My_Extraction_Folder” beneath the __Download folder, and saves a detailed log of the extraction process to extraction_log.txt.

PowerShell can extract zips on its own, but I’ve found the easiest way to capture the terminal output is to wrap the PowerShell command in a cmd.exe shell.

7 Likes

Thanks for sharing!

Small edge-case to be aware of is that Powershell cannot expand archives with files that are larger than 2gb which is tracked in the Powershell repo here: Add support for Zip64 for archives > 4GB · Issue #19 · PowerShell/Microsoft.PowerShell.Archive · GitHub

The issue only mentions compress-archive but it also applies to expand as is noted in several stack overflow posts like here: azure - Is there a file size limitation with Powershell Compress-Archive Zip using Windows Server 2016? - Stack Overflow

1 Like

Thanks for the tip! I wasn’t aware of that.
The archive I’m dealing with is 10 GB total but none of the individual files in the archive are that large.

2 Likes