Hei @learner Thanks for reaching out to Microsoft QnA.
Sorry for the delay in response.
If this is a script then it is possible that the step before this execution leads to a restart and the execution starts before the VM recovers.
The easiest way out of this would be to put a check that the VM is available, it is easy to do in powershell and azure cli script.
Also you could use a Infra as a code solution like bicep or terraform to do this, these solutions are resilient.
Please mark this as Answer , if it helped