Waiting for job to complete before starting another job when using the Start Job control

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
tphillipstx
Posts: 7
Last visit: Wed Apr 20, 2022 6:20 am

Waiting for job to complete before starting another job when using the Start Job control

Post by tphillipstx »

Product, version and build: PowerShell Studio 2019, version 5.6.159
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64 bit

I'm using the Button - Start Job control and have some jobs that need to wait until another job completes. For example, the first job creates accounts in a remote system and the account creation/replication needs to be confirmed before the next jobs can run. Is there an equivalent of Get-Job | Wait-Job in this control?

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Waiting for job to complete before starting another job when using the Start Job control

Post by jvierra »

You should use one job that does all of this. There is no mechanism for waiting other than the "Completed" script. You could use the completed script to start the next job but that doesn't really make much design sense.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Waiting for job to complete before starting another job when using the Start Job control

Post by jvierra »

Here are two methods that avoid waiting for replication to complete.

Code: Select all

# method #1
$domainController = Get-ADDomainController -Discover -Service PrimaryDC
New-ADUser .... -Server $domainController
Set-ADUser .... -Server $domainController

# method #2
$account = New-ADUser .... -PassThru
$account | Set-ADUser ....
tphillipstx
Posts: 7
Last visit: Wed Apr 20, 2022 6:20 am

Re: Waiting for job to complete before starting another job when using the Start Job control

Post by tphillipstx »

Thanks for the reply jvierra. A single job doesn't work for me. I have several jobs in my original PS script that connect to multiple remote PS sessions and having them run serially wouldn't provide any benefit time-wise.
Using the "Completed script" option sounds like the way I'll want to go.
This topic is 5 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked