Forum Discussion

abhi4vc's avatar
abhi4vc
Copper Contributor
Dec 27, 2024

Azure Virtual Desktop

Hi There 

Hope you are doing great!

I am new to Azure and Virtual Desktop and require some help to set it up correctly. 

I have created and setup the Virtual Desktop but looking for an option to automatically shut it down and deallocate, there is only 1 machine running and usually 1 user connects to it. if that user is not accessing the machine it needs to be deallocated after 30 or 15 min. 

Is it something anyone can help? 

Many Thanks 

 

  • Rg035's avatar
    Rg035
    Copper Contributor

    Definitely autoscaling in AVD would help you with this. If this is not a test environment and your setup is used by one person only. Look into windows 365, maybe this would fit your needs and would eliminate the need to shut it down.

  • You could look into the autoscaling capabilities on the host pool in AVD. have autoscale allocate and deallocate session hosts based on user load at the host pool.

    • Chris_toffer0707's avatar
      Chris_toffer0707
      Iron Contributor

      Just be aware that autoscaling on a host pool requires the session hosts to NOT use ephemeral disk, that is otherwise a great feature of session hosts in general.

  • ARMX86's avatar
    ARMX86
    Copper Contributor

    Hi there, the automatic shutdown is not instantly made, there can be a time difference for many reason. However, normally if you check the UI in operation to shutdown the vm after usage, it will shutdown by itself but there can be a time variation. You can also manually do it from different command center, shell or Admin center for example:

    If you are the admin, you can overseas the operation from Admin center, or from the terminal and you should get a faster response time if you manually do it.

     

    Still, the allocation for each resource are still "live" even if the vm is not running. 

     

    Best regards.

  • guptapankaj8's avatar
    guptapankaj8
    Copper Contributor

    Hello abhi4vc 
    I suggest to go with any 3rd Party i.e. Nerdio to manage your AVD environment. Its super easy and you can do it withing minutes as compare to Azure Portal.

    Thanks
    Pankaj

  • Salamat_Shah's avatar
    Salamat_Shah
    Iron Contributor

    Enable Auto-Shutdown for Virtual Desktop or VM:

    • Navigate to the Virtual Machine or Virtual Desktop in the Azure portal.
    • Under Operations, select Auto-shutdown.
    • Configure the desired shutdown time (e.g., set to 5:00 PM daily).
    • Optionally, enable a notification to alert you prior to the scheduled shutdown.

     

    • abhi4vc's avatar
      abhi4vc
      Copper Contributor

      Hi Thanks for your response I have tried this option, but it only shut it down on specific time which I have already enabled but what I am looking here is when machine is idea for 15 or 30 min and no user is connected it need to be shut down and deallocated automatically. 

       

      Is this an option? 

       

      Many Thanks 

      • balasubramanim's avatar
        balasubramanim
        Iron Contributor

        abhi4vc 

        To automatically shut down and deallocate your Azure Virtual Desktop after 15–30 minutes of inactivity, please try these steps

        1. Enable Diagnostics: Log user sessions to a Log Analytics Workspace.
        Go to the Azure Virtual Desktop blade in the Azure portal.
        Navigate to Host Pools > Diagnostics Settings.
        Enable diagnostics to capture user session information. Send logs to a Log Analytics Workspace.

        2. Use Automation: Create an Azure Automation Runbook that queries session activity from Log Analytics.

        3. Set Idle Logic: If no users are connected for the defined period, the Runbook stops and deallocates the VM.
        Go to Azure Automation Accounts and create a new account.
        Add the Az.Compute and Az.OperationalInsights modules.
        Create a Runbook and paste the script above.
        Test the script to ensure it works correctly.
        Create a schedule or trigger for the Runbook to execute every 15–30 minutes.

        Great Thought!. This ensures cost-efficiency and seamless management.

Resources