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?