PowerShell script exchange
Post Reply
deveritt
Lurker
Posts: 2
Liked: never
Joined: Aug 11, 2014 7:15 pm
Full Name: David Everitt
Contact:

Wait for Process to end

Post by deveritt »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Wait for Process to end

Post by veremin »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests