Wait for Process to end

PowerShell script exchange

Wait for Process to end

Veeam Logoby deveritt » Wed Aug 20, 2014 5:24 pm

I have a script that works when I open a prompt and run the script, It takes a VeeamZip then pushes that file to the cloud. When I try to use a scheduled task to run the script is doesn't wait for the Start-VBRip command to finish before moving on so nothing gets pushed to the cloud. Anyone know how to force the script to wait for that process to finish before moving on to the next? Thank you.

PARAM([string]$VMName)
asnp VeeamPSSnapin
$GlacierSync = "C:\Program Files\fastglacier\"
$Server = Get-VBRServer -name "10.1.2.6" | where {$_.type -eq "VC"}
$Entity = $Server | Find-VBRViEntity -name $VMName
$Path = "C:\VZips\" + $VMName
$GlacierPath = "GPBackups/" + $VMName

Start-VBRZip -folder $Path -Entity $Entity -Compression 9

forfiles -p $Path /D -13 -c "cmd /c del @path"

cd $GlacierSync
.\glacier-sync GPBackups $Path us-west-2 $GlacierPath nhs
deveritt
Lurker
 
Posts: 2
Liked: never
Joined: Mon Aug 11, 2014 7:15 pm
Full Name: David Everitt

Re: Wait for Process to end

Veeam Logoby v.Eremin » Thu Aug 21, 2014 8:48 am

Hi David, not sure why the script doesn't wait for session's end, as by default PS should execute commands in synchronous fashion. You can try to save the following portion as a separate script (say, "C:\Script\VBRZip.ps1"):

Code: Select all
PARAM([string]$VMName)
asnp VeeamPSSnapin
$Server = Get-VBRServer -name "10.1.2.6" | where {$_.type -eq "VC"}
$Entity = $Server | Find-VBRViEntity -name $VMName
$Path = "C:\VZips\" + $VMName
Start-VBRZip -folder $Path -Entity $Entity -Compression 9


And then refer to it via Start-Process commandlet within a script that is scheduled in Windows Scheduler. The Start-Process commandlet has -Wait parameter that might come in quite handy:

Code: Select all
$GlacierSync = "C:\Program Files\fastglacier\"
$GlacierPath = "GPBackups/" + $VMName
Start-Process -FilePath "C:\Script\VBRZip.ps1" -Wait
forfiles -p $Path /D -13 -c "cmd /c del @path"
cd $GlacierSync
.\glacier-sync GPBackups $Path us-west-2 $GlacierPath nhs


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests