Extracting a ZIP file in Powershell

brambo23

Member
I have a function that I found that will extract the zip files in powershell

I'm running this on a script on a remote machine that does not have powershell 2.0

function Extract-Zip
{
param([string]$zipfilename, [string] $destination)

if(test-path($zipfilename))
{
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
}
}

Example to use this function is: extract-zip c:\temp\test.zip D:\
I have a couple questions with this

1) When I execute this function, it doesn't return an exit code. Is there a way i can make the function force a exit code on completion or failure?

2) When I run the function, if there are files located where I want to copy them it will prompt me if i want to copy over them, and it gives a option to click cancel while the files are being extracted.

Is there a way I can remove the cancel option and just force it to overwrite any files that are there?

Thanks in advance
 

My Computer

Top