Share via

About Workflow

MeCRODevOps 1 Reputation point
2021-01-26T04:41:59.16+00:00

Hi there,

I'm new here, and recently I was scratch my head with something:

I'm wondering if a workflow can continue to run if the computer is rebooted. For example:
Workflow {
Do job 1
reboot
Do job 2
reboot
Do job 3
reboot
Do job 4
reboot
Do job 5
Reboot
done.
}

My question is, after each reboot, can the next job start or it will start from job 1? The workflow will be in a powershell script file which will be schedule to run every time the computer reboots.

Please help.
Thanks

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2021-02-01T05:37:20.327+00:00

    Hi,

    The -Wait parameter suppresses the PowerShell prompt and it's only for remote computers. You can try start-sleep

    workflow test {  
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 01"  
    Restart-Computer -force  
    Start-Sleep -Seconds 60  
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 02"  
    Restart-Computer -force  
    Start-Sleep -Seconds 60  
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 03"  
    Restart-Computer -force   
    Start-Sleep -Seconds 60  
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 04"  
    }  
    test  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. MeCRODevOps 1 Reputation point
    2021-01-31T06:30:03.49+00:00

    Thank you all for your help, I'm testing this script on a local computer:
    workflow test {
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 01"
    Restart-Computer -force -Wait
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 02"
    Restart-Computer -force -Wait
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 03"
    Restart-Computer -force -Wait
    Add-Content -Path "c:\bbc\bbc.txt" -Value "Task 04"
    }
    test

    I'm following these steps:

    1. on my computer, run this script, it will reboot
    2. after 1st reboot, I login and see Task1 and Task 02 in bbc.txt
    3. I'm expecting it reboots again, but it won't. When I check the job status by typing Get-Job, it shows suspended
    4. I have to manually resume the job, then it reboots again. When I login back, the file shows Task01, Task02, Task03, Task04, but the 3rd reboot didn't happen.

    Is there anything I did wrong?
    Thanks !!

    Was this answer helpful?

    0 comments No comments

  3. Rich Matheisen 48,116 Reputation points
    2021-01-26T21:05:53.453+00:00

    The answer is yes, but you'd have to add checkpoints to the workflow at the point you'd like it to resume. In the case of a reboot, you'd use the Restart-Computer with the -Wait parameter. I believe you'd also have to create a scheduled task that runs "AtStartup" that would resume the workflow if you don't want to do that restart manually.

    jj574130(v=ws.11)

    Was this answer helpful?

    0 comments No comments

  4. Anonymous
    2021-01-26T09:00:33.807+00:00

    Hi,

    It will start from job 1 after a reboot. To start from the next job, you can use the Restart-Computer cmdlet to reboot. It will create a job of type PSWorkflowJob and you can resume the workflow using the Resume-Job cmdlet.

    Restarting the Computer in a Workflow

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.