Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

Command:

$shellapp = new-object -com shell.application
$shellapp

Output:

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

Command:

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

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

Command:

$zipfile.copyhere("c:\temp\file.txt")

Output:

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

1 Answer 1

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\file.zip must already exist.

edit:

function New-Zip
{
    param([string]$zipfilename)
    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.