Thursday, 17 July 2008


    This script zips a particular file into an existing archive (zip file).
    For this script, c:\foo\ must exist
    The script zips c:\test2.txt into c:\foo\
    File Name  : Zip-File.ps1
    Author     : Thomas Lee -
    Requires   : PowerShell V2 CTP3

# Start of Script

# Get shell object and check to see that file exists
$sh = new-object -com shell.application
$fl = get-childitem c:\foo\ -Ea 0
if (!$fl)
   'File does not exist - stopping'

# Get Zip File to zip into
$targetzip = $sh.namespace("C:\Foo\")   # where the item is to go

# Copy a file into this zip

# Check it now exists
ls c:\foo\
# End of Script


Alex said...

At operation with zip files recommend to use modern tools,on example this application-repairing zip file with cyclic redundancy error,I finded it in google when I had been problems with zip file,utility is free as far as I know,it can extract needed document from corrupted archive and repair it,will successfully recover all documents,works faster and recovers more documents, than other services,program works under all supported versions of Microsoft Windows operating system,will mark all files for zip crc failed repair and zip archive crc repair,repair zip files crc error and you'd like to save recovered data,also possible to select your Zip file from the list of previously recovered archives.

Alex said...

I received on mail zip file,but it was corrupted,accidentally in one inet portal I found-zip files and does not appear to be a valid archive.And program helped me and it has free status,moreover program for extracting zip files 2gb Microsoft,also can extract your documents from corrupted Zip files.

Som said...

Don't use copyhere method anywhere in your code. It produces GUI Message-box and you will never know why your script failed.
So script might lead to an inconsistent state.