Zipping only files using powershell
        Posted  
        
            by 
                SteB
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by SteB
        
        
        
        Published on 2012-12-07T15:50:42Z
        Indexed on 
            2012/12/10
            11:10 UTC
        
        
        Read the original article
        Hit count: 249
        
powershell
|zip
I'm trying to zip all the files in a single directory to a different folder as part of a simple backup routine.
The code runs ok but doesn't produce a zip file:
$srcdir = "H:\Backup"
$filename = "test.zip"
$destpath = "K:\"
$zip_file = (new-object -com shell.application).namespace($destpath + "\"+ $filename)
$destination = (new-object -com shell.application).namespace($destpath)
$files = Get-ChildItem -Path $srcdir
foreach ($file in $files) 
{
    $file.FullName;
    if ($file.Attributes -cne "Directory")
    {
        $destination.CopyHere($file, 0x14);
    }
}
Any ideas where I'm going wrong?
© Server Fault or respective owner