Remotely zipping files with PowerShell start-process and invoke-command

Question:

I want to be able to remote into a system and zip or unzip files there and have the process signal when it is complete. Start-process works with the -wait parameter to run 7z.exe synchronously from PowerShell. When I try to combine that with invoke-command to run the same command remotely, it does not honor the wait parameter and I believe it is killing the process since it returns quickly and never produces a zip file.

I originally tried the PSCX write-zip & expand-archive, but the latter is not compatible with 64-bit .NET 4.0 configuration. So now I’m trying to call 64-bit 7z.exe through the command line. I’m not receiving any errors. PowerShell reports the job as running state and then complete, and no zip file is produced.

Appreciate any help or pointers.

Thanks,
Gregory

Answer:

Since Start-Process will be used synchronously here, I would recommend avoiding it and just use the 7z.exe executable:

Doing so will naturally block your script until 7zip completes its job.

Source:

Remotely zipping files with PowerShell start-process and invoke-command by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply