Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following example doesn't seem to work on my Windows Server 2008 SP2 nor my Windows 7 Pro Sp1.


$shellapp = new-object -com shell.application


Application         Parent
-----------         ------
System.__ComObject  System.__ComObject


$zipfile = $shellapp.namespace("c:\temp\")

Output: No output? (I'm assuming it didn't work and $zipfile is null)




You cannot call a method on a null-valued expression.
At line:1 char:18
+ $zipfile.copyhere <<<< ("file.txt")
    + CategoryInfo          : InvalidOperation: (copyhere:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I've tried to re-associate .Zip with the instructions: How to restore Windows default Zip file functionality?.

I've also tried to re-register with regsvr32.dll zipfldr.dll with no success.

share|improve this question

closed as off topic by mdpc, Ward, Khaled, mulaz, Tom O'Connor Jan 7 '13 at 11:04

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Where did you get the example from? – Dan Jan 6 '13 at 22:46
up vote 1 down vote accepted

This is not creating a new zip file. This is adding files to an existing zip file. In your example, C:\temp\ must already exist.


function New-Zip
    set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
    (dir $zipfilename).IsReadOnly = $false
share|improve this answer
So how do I create a zip file using powershell and built-in functionality only? – Erik Philips Jan 6 '13 at 22:50
Edited my post. Like that. – Ryan Ries Jan 6 '13 at 22:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.