I have written a PowerShell script that zips the contents of a folder and sends it to a server for backup. The issue is that the copy process doesn't wait for the zip process to finish. I have tried using Out-Null
and Wait-Process
, and nothing seems to be working. Out-Null
just doesn't do anything, and Wait-Process
tells me that no such process exists. I can't seem to figure out the process name for the Windows Compression. Any help would be greatly appreciated. Below is the part of the code I would like to have paused until it finishes.
function out-zip {
Param([string]$path)
if (-not $path.EndsWith('.zip')) {$path += '.zip'}
if (-not (test-path $path)) {
set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}
$ZipFile = (new-object -com shell.application).NameSpace($path)
$input | foreach {$zipfile.CopyHere($_.fullname)}
}
gi "C:\File-Backups\Share1" | out-zip C:\File-Backups\transfer\PC1-Backup