Hi guys, first question in this forum.
I have created a script for backing up file-stores and databases, then copy the content into a zip-file.
I really want the powershell window "sleep" while the zip-process is compacting, but I am not getting the results I want.
To me it looks like the wait-job is waiting for the the jobs running in the back ground. But the Job ends after sending commands to a different process (compressing) and exits premature.
This is my code:
$filepath1 = "F:\Music\"
function zipIT{
write-host "Starting ZIP job, might complete after script is finished" -ForegroundColor Green
Set-Content F:\backup\mytest.zip ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
$File = Get-ChildItem F:\backup\mytest.zip -ErrorAction SilentlyContinue
$File = (New-Object -COM Shell.Application).Namespace($File.FullName)
$File.CopyHere($filepath1, 4)}
$myZipIT = zipIT
Start-Job -name SnoreIT -ScriptBlock {$myZipIT}
Get-Job -IncludeChildJob | Wait-Job
I get the following information in the shell:
PS F:\Lync scripts> & '.\sleep time.ps1'Starting ZIP job, might complete after script is finished
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
22 SnoreIT BackgroundJob Running True localhost $myZipIT
22 SnoreIT BackgroundJob Completed True localhost $myZipIT
23 Job23 Completed True localhost $myZipIT
Finished
Problem is: job reports completed but the compressing process is not over (I guess PS has handed it over to a different process, and no longer regard the the job as running.
You guys have any ideas how to handle this? It's the last piece to my puzzle, which I need to use this script in a fully automated way. (When running the script as it is, the scheduled task exits prematurely and the zipfile is corrupted)
Kind regards,
Lasse
Lasse Wedø,
Blog:Tech@work, Twitter: @lawedo
Please take a second to hit the green arrow on the left if the post was helpful, or mark it as an answer if it resolved your issue.