Extracting a ZIP file in Powershell

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


-- 
brambo23
0
brambo23
5/25/2010 5:43:41 PM
windows.powershell 690 articles. 0 followers. Follow

3 Replies
5404 Views

Similar Articles

[PageSpeed] 11

Hello "brambo23".

"brambo23" wrote:
> 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?

No, the CopyHere method does not return anything.

> 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.

You could try the second parameter of the CopyHere method:
$destinationFolder.CopyHere($zipPackage.Items(), 16)
http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx

-- 
Regards,
Wolfgang


0
Wolfgang
5/27/2010 2:54:44 PM
On 5/27/2010 9:54 AM, Wolfgang Kais wrote:
> http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
>

Does anyone know when PowerShell examples are going to be added
by Microsoft to webpages like that one?

  - Larry
0
Larry__Weiss
5/27/2010 4:51:12 PM
According to the helpfile 

http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx

CopyHere(vItem,[ vOptions ])

set Options to 16

"brambo23" wrote:

> 
> 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
> 
> 
> -- 
> brambo23
> .
> 
0
Utf
5/27/2010 7:57:20 PM
Reply:

Similar Artilces:

MDI App will no longer open file by double clicking associated filetype
OK, I had an app which was originally based upon an MDI app. It has been 'modded' to add various functionalities with code from www.codeguru.com and www.codeproject.com. Unfortunately, I just recently noticed that the ability to double click on the associated filetype (from a folder, desktop, etc) now no longer works. Instead, I get a messagebox: Title: (pathname of file) Message: Windows cannot find '(pathname of file).' Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search. This is on Windows XP. ...

extracting totals from within a spreadsheet
I need to know how to take different information from within a spreadsheet --where two conditions/catogories must apply so that a third column where i have inputed hours, will total for those conditions only... can anyone help? Please spell out what you want we are not mind readers -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "Jovetta" <Jovetta@discussions.microsoft.com> wrote in message news:91442C6D-03DF-4FC1-A069-AAB43FA57485@microsoft.com... >I need to know how to take different information from within a spreadsheet > --where two condi...

extracting icons
Is there any way to extract an icon from an application? Take a look at the ExtractIcon[Ex]() API Cheers Check Abdoul --------------------- <davegreb@gpxinc.com> wrote in message news:c6c54da6-574c-4c8e-8ec9-3b77b99a5523@d70g2000hsb.googlegroups.com... > Is there any way to extract an icon from an application? ...

How exchange files with Adobe InDesign for Mac OS?
I'm using Pub 2000 for Windows, and a coworker in another office exclusively uses Adobe InDesign for Mac OS. I want her to send me a template for a document I need to develop (in Pub 2000). Can she, and if so, in what format(s)? Have her save it as a .pict or .eps. You will have to insert the template as a picture. Look at the different picture formats Publisher can use. You probably then can reconstruct the objects in Publisher. I'd be interested to know how you work this out. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft....

Random numbers, Canadian Zip Code style #3
Cool, I'll give it a try. Thank you very much. Le -- Shocke ----------------------------------------------------------------------- Shocked's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1489 View this thread: http://www.excelforum.com/showthread.php?threadid=26523 ...

Excel: extract and sum numerals from mixed text/numeral cell range
I have a large (30x20) grid of cells with data, and I want to extract and then sum up certain numerals from this entire range. The catch is that the data is mixed numerals and text, as you'll see below. Here's an abbreviated 3x3 example, with a value in each of the nine cells: V7.1 T H P1 A T B V3 P4.5 If I just wanted to sum up the instances of "T" appearing, I could use COUNTIF() for the entire range to come up with answer ("T" appears 2 times). Easy enough. But, what I'm trying to accomplish is to sum up the numerals associated w...

Extract emails from cells with text
I have a row in column A which includes an email address in the text that I'd like to extract to column B. Is there a formula I can use to accomplish extracting the email address only to column B? Here's an example of different cells in column A: Please email example@law.ufl.edu to contact us...... OR Schedule an appointment for assistance, or email example@uga.edu with your questions... Thank you Try this... All on one line: =TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND (" ",A1&" ",FIND("@",A1))-1)," ", REPT(" ",...

Outlook express files gone
I started up outlook express today and i have no view, and cannot get a view of all the files, inbox, outbox etc. The only way I can see my emails is by going into file and open then clicking next or previous! Any ideas?? Submitted via EggHeadCafe - Software Developer Portal of Choice Easy "NO SCRIPT" DataGrid Tooltips in ASP.NET http://www.eggheadcafe.com/tutorials/aspnet/c0d39393-80fe-481f-af5c-0e18fa4e2e43/easy-no-script--datagri.aspx View | Layout. Is: Folder List checked? -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Ian Va...

FRx 6.7 Analytical Accounting Add-In.zip
Can someone direct me to the correct location of the FRx 6.7 Analytical Accounting Add-In.zip file? I downloaded this Analytical Acct'g file for FRx SP 10, FRxsps67010343_aa.zip, but it does not contain the "FRx 6.7 Analytical Accounting Add-In.msi". I'm having a hard time finding it. ...

total size of files
I need a script to find out the number & total size of files based upon the file extention across about 30 servers. I'm searching for mdb files. The script will be run remotely against local drives on these servers. Thanks On Nov 18, 10:19=A0am, Tom1 <usernetu...@yahoo.com> wrote: > I need a script to find out the number & total size of files based > upon the file extention across about 30 servers. I'm searching for mdb > files. The script will be run remotely against local drives on these > servers. Thanks <warning> <aircode> with ...

old money files
I can't access old money files. The error message says it's the wrong password (I must have changed it since then). How do I access them if I used a different password back then? In microsoft.public.money, leenman wrote: >I can't access old money files. The error message says >it's the wrong password (I must have changed it since >then). How do I access them if I used a different >password back then? What version of Money are you now using? What version of Money were those older files created with? >-----Original Message----- >I can't access o...

Compress seq data from txt-file into 15 min chunks in another file?
Hi I want to compress "tick"-data (ie trades) from a file into another file. In the target file I want to chunk the data into 15 minutes activity (or other number of minutes) and summorise it into date, time, open, high, low, open and volume. I have managed it with days but minutes is harder. I have 3 cells in a worksheet that I have given the names: Sourcefile, Sourcefolder and Targetfolder. And I have added "eod" (EndOfDday) at the beginning of the target file. Below have I put parts of the sourcefile and the targetfile for days for that sourcefile. As I wr...

Export/Import Acces Table to another Acces table/file
Hi, Is anybody can help me how to export/import table to a new table/file only using 1 click?. I am sure, we'll use Visual Basic, but I don't know how. Thanks in advance, I am appreciated it. KT -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200707/1 I suspect you will need to look at the TransferDatabase method of the DoCmd object. See the Access help. Steve "KimTong via AccessMonster.com" wrote: > Hi, > > Is anybody can help me how to export/import table to a new table/file only > using 1 ...

Query and Extract
Hello all, This seems basic, but I just cannot get it. While using SQL Server 2005 and the Microsoft SQL Server Management Studio, I created a database called AssetQuote. Inside I have on table called assetquotes. From there, I have three columns, (date, quote, author) The column type for date is datetime and the other two are just text. My Query is something this: INSERT INTO AssetQuote (date, quote, author) VALUES('052010','No act of kindness, no matter how small, is ever wasted.', 'Aesop'); When I run the query I get this result: Msg 208, ...

extracting individual numbers from "ranges"
I'm trying to get EXCEL to extract stock prices quoted in individual cells as 52-week ranges --e.g. 11.76-19.90-- and do the following calculation: (higher price - lower price)/lower price Obviously, this a problem because each cell appears to handle the range as text or something. Is there are way to get EXCEL to handle the "text" (or however else it is interpreting what's in the cell) as individual numbers? Great thanks for any help. Hi do your entries always look like lower_number-higher_number if yes you may try the following formula in the adjacent row (lets assum...

Great Plains-error "Files for this company have not been updated"
I have installed great plains ver. 8.0 for a database that has different language (arabic). I have replaced all the arabic dic files with the english files. It is running fine on the default company (fabrikam) but is not running on the customized company database and generating the following error: "Files for this company have not been updated" Can any one help me in this regard. Hi Walliullah, Sounds like it may be a problem with a service pack. Make sure that the service pack version on the server matches the service pack version on the client. That is usually the source of ...

Excel 2003 step by step book files
Does Microsoft have a place where I can download the files for Excel 2003 Step by Step? I lost the CD. I looked here http://www.microsoft.com/mspress/books/5605.asp but I don't see anyplace for downloading the files. ...

Archive hosed my Money 2003 File!
Around the first of the year, I archive my Money 2003 file and it messed up my checking account to the point where I have to change the starting balance when I reconcile. It seems that Money archived all transactions older than 1/1/2005, regardless of whether they were reconciled yet or not! I could complain about that forever it ticks me off so much. I manually added back the transactions that were still outstanding and if I fudge the starting balance each month, I am able to reconcile as long as I take the "ignore differences" option when I am balanced by my reckoning. My quest...

CFileDialog file filter
Using the MFC, how do I "filter" files using the CFileDialog Class? eg. use the "Files of Type" Option List? eg, If I only want to list *.doc files? What member function or other class / object interaction do I need? I'm using MS VS C++ .NET 2003 standard. Thanks all in advance. Hi There, Flags can be set in the format "<Type Text>|*.ext.....|". e.g you can set "MS Word Docs|*.doc|". Note that string ends with a '|' otw you'll see an extra junk entry in the file type combo.. HTH Ashish "Simon Flannery" <support@...

Restore Backup Files
Hi there I have posted this question to the Windows XP Professional x64 Edition board and the microsoft.public.windowsxp.help_and_support board as suggested by other users. Some time ago I set up the Backup feature on Windows XP Pro so that my laptop data got backed up daily to an external hard drive. The laptop was recently stolen but thankfully, the external hard drive was left behind and I have a Mac desktop computer with Bootcamp. When I restore the backup.bkf file, the directories are all there, but there is no data - not a Word, Excel, PDF or any other type of file to ...

extracting hours from a sum of time
I have a cell which sum a bunch of cells containing an elapsed time. The sum totals to more than 24 hours. I have to a cell with a cost per hour and I need to caclculate the total cost. The problem is that the hour function returns values in the range of 0-24. My current sum is 25:30 and the hour function return 1 and not 25. Any ideas how to bypass it? It "returns" the correct number, but doesn't show. Format Custom as [h]:mm and it will. To convert to a number that you can multiply with an hourly rate, first multiply by 24; times in Excel are fractions of a day and a day is s...

I can not email excel files
I am using xp- I can"t email a excel file? newbe wrote: || I am using xp- I can"t email a excel file? Umm what happens when you try? -- Interim Systems and Management Accounting Gordon Burgess-Parker Director www.gbpcomputing.co.uk And what are you doing to try?? -- Don Guillett SalesAid Software donaldb@281.com "newbe" <newbe@discussions.microsoft.com> wrote in message news:4EBA3AC3-F379-4973-AB64-FBA9FD7F43A5@microsoft.com... > I am using xp- I can"t email a excel file? i was trying to e mail right out of excel but it would not work. I found out...

Why does the flowcharts go out of alignment when I open the files?
I have created flowcharts which appear fine when I work on them and save them. Subsequently, when I reopen the files, the alignment of the process and text boxes move from the original saved drawing. I have got our IS support to reinstall visio with an updated version of visio 2000 but this still happens. Appreciate any help in this area. Thanks! ...

Extract Text
Dear all I have this text in a field: 200701-I 200701-II 200701-III 200701-IV and I need to separate only the data after the six first data: -I -II -III -IV How can I do it? Thanks a lot!!! Andr=E9. Take a look at Access HELP for the Mid() function. Open a query in design view and add a new field something like: NewField: Mid([YourField],7) -- Regards Jeff Boyce www.InformationFutures.net Microsoft Office/Access MVP http://mvp.support.microsoft.com/ Microsoft IT Academy Program Mentor http://microsoftitacademy.com/ <gatarossi@ig.com.br> wrote in message news:11893397...

Can I extract unique cell values from every nth column?
I have a range that covers B5:XA160. For each row, data is entered in 11-cell groups: date, some numbers, description (a text value), more numbers, and more numbers. At first it was enough to merely count how many times certain descriptions appeared, because those were the only ones we would see - or so the story went. Now, I need to extract the unique descriptions AND provide a count! Actually, I'm cheating a bit. I'm using SUMPRODUCT to return the number of times the expected descriptions appear, and by subtracting these from the total number of text values I get a count of &quo...