I want to extract all .zip files in a given directory in temp using powershell

You can use this if you want to create a new folder for each zip file:

#input variables
$zipInputFolder = 'C:\Users\Temp\Desktop\Temp'
$zipOutPutFolder = 'C:\Users\Temp\Desktop\Temp\Unpack'

#start
$zipFiles = Get-ChildItem $zipInputFolder -Filter *.zip

foreach ($zipFile in $zipFiles) {

    $zipOutPutFolderExtended = $zipOutPutFolder + "\" + $zipFile.BaseName
    Expand-Archive -Path $zipFile.FullName -DestinationPath $zipOutPutFolderExtended

    }

Get-ChildItem 'path to folder' -Filter *.zip | Expand-Archive -DestinationPath 'path to extract' -Force

requires ps v5


You have to provide the full path explicitly (without wildcards) in the following call:

$shell.NameSpace($file)

You could rewrite your function like this:

function Expand-ZIPFile($file, $destination)
{
    $files = (Get-ChildItem $file).FullName

    $shell = new-object -com shell.application

    $files | %{
        $zip = $shell.NameSpace($_)

        foreach ($item in $zip.items()) {
           $shell.Namespace($destination).copyhere($item)
        }
    }
}