howtogeek — 2013-06-13T12:36:02-04:00 — #1
Originally published at: http://www.howtogeek.com/tips/how-to-extract-zip-files-using-powershell/
Windows includes the ability to unzip archives and even exposes this functionality programmatically via COM. Here is how to do it.
raphoenix — 2013-06-13T14:59:21-04:00 — #2
Instead of auguring about Windows 8, maybe this would be a better use of one's time. )
Click on the Link above.
iszi — 2013-06-13T15:51:02-04:00 — #3
I think I'll still prefer 7-Zip over PowerShell for this. Nice to know the capability is built-in to the OS though.
netpilot — 2013-06-14T10:32:27-04:00 — #4
@raphoenix Anyone can find books on the subject. The trick is to find a good, current one. Do you own any of those books or do you recommend one or two over the others?
@Iszi I agree that I wouldn't use the example by itself instead of 7-Zip, but If you are going to do something further to the unzipped files in a larger PowerShell script, the code snippet will be really useful.
raphoenix — 2013-06-14T14:30:18-04:00 — #5
PowerShell is such important program included with Windows 7 and 8, I feel it is extremely important to learn the program.
Yes I own PowerShell books.
Recommend the 5 Star Books in the Amazon Link posted above.
May be we should have a Topic Named "What are you reading this Summer ?".
davidruhmann — 2013-06-24T16:31:21-04:00 — #6
This PowerShell unzip ability is further enhanced by the optional second parameter for the CopyHere function.
I use vOption = 16 in my scripts. (Yes to All prompts)
PowerShell (New-Object -COM Shell.Application).NameSpace('DESTINATION').CopyHere((New-Object -COM Shell.Application).NameSpace('ZIPFILE.zip').Items(), 16);
iszi — 2014-01-10T14:20:18-05:00 — #7
So, now that I've warmed up to PowerShell more recently, I actually ended up using this bit the other day to talk a Server Admin out of installing 7-Zip on a system that needed a command-line utility to extract a ZIP file in a batch job.
(I have zero objections to 7-Zip personally - in fact, I stated my preference for it earlier in this thread - but professionally, part of my job is ensuring that systems adhere to the security principle of Least Functionality. That is, essentially, you should avoid installing additional software whenever possible.)
A limitation I did find is that the command doesn't seem to be able to handle ZIP files which have an internal folder structure. Fortunately, that was not an issue for this particular use case.
bdmeyersc — 2014-07-10T17:01:36-04:00 — #8
I hope this isn't improper etiquette to revive this old topic. I wanted to maintain continuity of the discussion as one of the comments is giving me hairballs. I created the function per the example, and it works great. Unfortunately, by design the system that creates the zip files includes duplicate file names for some of the files inside the zip file. Before scripting it's simple to select 'copy and rename| repeat for all the others. That would be folder.copy option 8:
"(8) Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists."
When I insert either 8 or 16 (yes to all prompts) I have some amazing things appear in my test directory. Like copies of shortcuts, recently used files.
I'll post my codes, and hopefully someone can point out the error of my ways:
Function to unzip files
function UnZipper($file, $destination)
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
Then I call it with:
UnZipper -File $caseDrive\$caseName.zip -Destination $caseDrive
and that works perfect, except my duplicate files get ignored and disappear.
Next On this line:
foreach($item in $zip.items())
foreach($item in $zip.items(), 8)
and that's when the hairballs occur.
I am wondering if I need to add 4096 to the value based on:
So I tried it with 4102 and this time I got the 'Favorites' folder in the middle of my extraction.
Also the 'Copy and Replace?" popup comes up. So I added an 8 (4110)
No change except instead of Favorites, I got "My Videos" folder.
I added 4 (4114) and didn't get the prompt for Copy? but still got the progress bar, unexpectedly.
If anyone has an idea, I would be quite pleased for the help.
geek — 2014-07-11T03:54:05-04:00 — #9
This topic is now closed. New replies are no longer allowed.