Can we run powershell script to shutdown the vms automatically?

Krishna Aswin 40 Reputation points
2024-05-17T08:53:23.3+00:00

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,319 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,185 questions
0 comments No comments
{count} votes

Accepted answer
  1. v-vvellanki-MSFT 4,680 Reputation points Microsoft Vendor
    2024-05-17T09:16:03.75+00:00

    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,115 Reputation points Microsoft Vendor
    2024-05-17T09:27:15.03+00:00

    Hello,

    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