I've been experimenting with Powershell Workflows and come across behaviour I can't seem to figure out. When using Restart-Computer with the -Wait switch the documented behaviour should be that the workflow suspends and can be continued later with the Resume-Job cmdlet (after importing the PSModule Workflow).
What actually seems to happen, at least on the Server 2012 evaluation VM I'm using, is that the workflow blindly continues without waiting resulting in incorrect behaviour.
The behaviour can be seen by the following test script:
workflow test-restartbug {
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot1.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot2.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot3.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot4.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot5.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot6.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot7.txt"
Restart-Computer -Wait
Get-Date | Set-Content -path "c:\scripts\reboot8.txt"
}
test-restartbugWhich creates some (occasionally all 8) text files in one go, after just a single restart. If the workflow didn't get all the way through, then there is a suspended job, otherwise not.
Am I missing something blindingly obvious, or is this a bug?