My Azure VM sometimes gets deallocated for some reason, so I created a PowerShell script and configure it as a scheduled task to monitor the VM status and start the VM once it is deallocated. The script uses a precreated Azure service principal
to automatically authenticate Azure and Azure PowerShell cmdlets
to detect the VM status, if the status is deallocated
then it calls Start-AzVm
to start the VM, the script execution result is recorded to a log file.