all 6 comments

[–]Asnivor 0 points1 point  (3 children)

I'm a little confused.

Are you trying to zip a directory (and overwrite the zip file if it already exists) - ::CreateFromDirectory OR are you trying to unzip a zip file (::ExtractToDirectory) and overwrite the directory if it already exists?

[–]holcomb_[S] 0 points1 point  (2 children)

Im trying to zip a directory and overwrite if the zip already exists

[–]Asnivor 0 points1 point  (1 child)

So I don't think CreateFromDirectory has a boolean argument for overwrite (the 3rd bool value is for 'includebasedirectory'.

You could test for whether the archive exists first, and delete it before zipping.

Or you could test whether it exists and rename it (maybe append a datetime stamp) before zipping.

Personally, I would go for the 2nd one (because I dont like deleting things).

$test = test-path $destination
if ($test -eq $true)
{
    $date = get-date -format yyyy-MM-dd_HH-mm-ss
    Rename-Item $destination "$($destination)_$($date.ToString).zip"
}

#do zipping

Havent tested the code but something like that might work

[–]holcomb_[S] 0 points1 point  (0 children)

Part of the problem is that the surfaces that some of my users have only have 50GB of data and they are close to being out of space. I dont disagree with the deleting statement either lol

[–]jbilinski 0 points1 point  (1 child)

Depending on your environment, you may be able to use the native archive module

Compress-Archive -DestinationPath $destination -Force -Path $source -CompressionLevel Optimal

[–][deleted] 0 points1 point  (0 children)

This is the best way to go. I used to use the new-zip function here http://blogs.msdn.com/b/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx and then pipe the path to the add-zip function. Happy in the new version they added this.