Script to shutdown Virtual Machine for users

Anga Dcruz 40 Reputation points

Is there any script that help to shutdown the VM in azure
for users

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
5,977 questions
Azure Virtual Desktop
Azure Virtual Desktop
A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.
1,192 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,325 questions
0 comments No comments
{count} votes

Accepted answer
  1. dashanan13 535 Reputation points

    Hei Anga Dcruz,

    Thank you for contacting Microsoft community.

    A user will need "VM Contributor role" or a custom role with privileges to power off\on, if they need to shutdown a VM via a portal or powershell or azure command line.

    It is also possible to schedule a shutdown through "auto shutdown" feature, available in the left menu for vm under "Operations" > "Auto shutdown".

    Connect-AzAccount   #Authenticate to Azure 
    Set-AzContext -Subscription <subscription name>   # set the correct subscription
    Stop-AzVM -ResourceGroupName <Resource group> -Name <Virtual machnie name>

    Read more about build in VM roles:

    Read about setting custom roles:

    Read about assigning roles to an account:

    Read about auto shutdown:

    Please mark this as "answer" if it helped.


    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Johan Vanneuville 81 Reputation points MVP

    Do you need it for normal virtual machines or for AVD session hosts?

    For normal vm's you can use the auto shutdown feature.

    Otherwise you can use scaling plans for AVD:

    0 comments No comments