Hey everyone! I'm looking for a way to automatically shut down my Azure VM (specifically a Windows 10 instance) after the user connected via Azure Bastion is inactive for a certain period of time. The goal is to monitor session activity and then stop and deallocate the VM to avoid incurring costs.
I've done some research but found that suggestions from Copilot were either outdated or didn't address inactivity detection specifically, focusing instead on CPU metrics, which aren't reliable due to various background processes. Here are a few ideas I'm considering:
1. Installing third-party software on the VM to track user activity, which would then trigger shutting down or hibernating the VM, but I also need to deallocate it to prevent billing.
2. Utilizing a Windows native feature to log off inactive users (any tips on how to do this?), and then triggering a shutdown or hibernation after logoff, followed by auto deallocation.
3. Using an Azure-native feature that directly monitors user session inactivity to manage proper shutdown and deallocation, keeping the disk intact (essentially just stopping the VM).
I'm currently exploring the Azure-native solution, but I'm having trouble activating guest-level monitoring due to an Identity setup requirement I can't seem to get right. Thanks for any insights or ideas you can share!
1 Answer
You should give your VM a system identity and assign it the necessary rights, then run a task scheduler script to automate the shutdown. Alternatively, you could create an Automation Account that already has a premade solution for shutting down based on inactivity.
Task scheduler? Are you suggesting setting a timed shutdown? That won't work since the user connects randomly as needed.