PowerShell is an awesome tool which allows to do a lot of things. But sometimes there is some empty spaces which we are not able to figure straightforward.

Having to unzip a folder where there was also subfolders may become somehow harder than it should.
Natively PowerShell has command Expand-Archive which allows to decompress zip folders. However if there is any subfolder on zip file, it will be missing. It happens that as the time of writing this post it iwill just decompress first level files, no sub folders and files descendants.

There is another call you may use based on .Net framework

Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
    param([string]$zipfile, [string]$outpath)

    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

Unzip "C:a.zip" "C:a"

However this way also fails to extract folder structure.

You may build your own Unzip based on well know opensource 7-Zip.
Have console Binaries of 7-zip in a folder

image

Then have a module script:

$ZipCommand = Join-Path -Path (Split-Path -parent $MyInvocation.MyCommand.Definition) -ChildPath "7za.exe"
if (!(Test-Path $ZipCommand)) {
        throw "7za.exe was not found at $ZipCommand."
}
set-alias zip $ZipCommand

function i9unzip {

        param (
                [string] $ZipFile = $(throw "ZipFile must be specified."),
                [string] $OutputDir = $(throw "OutputDir must be specified.")
        )


        
        if (!(Test-Path($ZipFile))) {
                throw "Zip filename does not exist: $ZipFile"
                return
        }
        
        zip x -y "-o$OutputDir" $ZipFile
        
        if (!$?) {
                throw "7-zip returned an error unzipping the file."
        }
}

We named it i9unzip.

Now on your main code you may just use it and unzip will behave as expected – keeping zip structure on extracted folder .