Can we run powershell script to shutdown the vms automatically?

Krishna Aswin 40 Reputation points

I know we have auto shutdown option provided by azure to auto shut down the VM's at perticular intervals. But I have achieve this by running a script. Can anyone help me with the powershell script.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,370 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,216 questions
0 comments No comments
{count} votes

Accepted answer
  1. v-vvellanki-MSFT 4,915 Reputation points Microsoft Vendor

    Hi @Krishna Aswin ,

    Thanks for contacting Microsoft Q&A platform.

    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".
    You can also operate VM's using below Powershell Query.

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

    Hope this helps you.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jing Zhou 3,435 Reputation points Microsoft Vendor


    Thank you for posting in Q&A forum.

    Please let me know if this is what you want:

    Powershell script to auto shutdown virtual machines. - Microsoft Q&A

    If there are any misunderstandings, please contact me.

    Best regards,

    Jill Zhou

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments