Download zip file, extract and overwrite windows 2008 r2

3.3k Views Asked by At

I have been looking for a way to download a zip file from a URL, have it extracted to a destination folder and then overwrite any files which are the same. I looked at powershell scripts but could not get one to work.

Working on a windows 2008 r2 server. Any insights would be great on the most efficent, easiest way to achieve this

cheers

1

There are 1 best solutions below

1
On

If you download and install 7Zip form here, then use the following PowerShell command that uses the 7z.exe file. You will be able to unzip and overwrite files to a given location.

$ZipFile = "T:\file1.zip"
$zipToFolder = "C:\UnzipToThisFolder\"
& "c:\program files\7-zip\7z.exe" x $ZipFile -o"$zipToFolder" -y

Parameters:

x: extract files with full paths
-o{Directory}: set Output directory
-y: assume Yes on all queries (Overwrites)

If the zip file you want to unzip is on a website you will need to download the file first and then unzip it. You can download files from a website in PowerShell like this:

$source = "http://www.site.co.uk/something/Yourfile.zip"
$destination = "C:\DownloadTo\Folder\fileNAme.zip"

Invoke-WebRequest $source -OutFile $destination