0

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.

2

1 Answer 1

1

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
} 
2
  • So how do I create a zip file using powershell and built-in functionality only? Jan 6, 2013 at 22:50
  • Edited my post. Like that.
    – Ryan Ries
    Jan 6, 2013 at 22:50

Not the answer you're looking for? Browse other questions tagged .