Powershell – How to unzip a file in Powershell

powershell

I have a .zip file and need to unpack its entire content using Powershell. I'm doing this but it doesn't seem to work:

$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace("C:\a.zip")
MkDir("C:\a")
foreach ($item in $zip.items()) {
  $shell.Namespace("C:\a").CopyHere($item)
}

What's wrong? The directory C:\a is still empty.

Best Answer

In PowerShell v5+, there is an Expand-Archive command (as well as Compress-Archive) built in:

Expand-Archive c:\a.zip -DestinationPath c:\a