> ## Content Index
> Fetch the complete content index at: https://blog.viveknet.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Automating Azure VM Shutdown and Startup
- URL: https://blog.viveknet.com/automating-azure-vm-shutdown-and-startup/
- Published: 2024-10-28T09:00:00.000Z
- Updated: 2026-10-04T06:55:48.000Z
- Author: Vivek Chandran
- Tags: Azure

## Introduction

Recently, I received a request at work to implement an automated solution for shutting down and starting up Virtual Machines at specified times to optimize costs. While the initial thought was to use Windows Task Scheduler on a server, this approach had limitations:

- Requires a dedicated always-on Windows server
- Single point of failure
- Limited monitoring capabilities
- No built-in high availability

Azure Automation Account emerged as a superior solution because it offers:

- Serverless execution
- Built-in high availability
- Comprehensive monitoring
- Native Azure integration
- Cost-effective implementation

## Prerequisites

- An Azure subscription with active credentials
- A running Virtual Machine in Azure
- Appropriate permissions to create and manage Azure Automation resources

## Implementation

### 1\. Creating an Azure Automation Account

1. Navigate to the Azure Portal
2. Search for "Automation Accounts"

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/c5e4d3f6f9c7942e64ada3c5d0308651.png)  
4\. Click **Create** and configure the following:

- **Name**: Choose a unique name
- **Resource Group**: Select or create new
- **Location**: Choose same region as your VM
- Click **Review + create** followed by**Create**

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/6bdfa58cb97a7fb38e8d542acb014445.png)

1. Assign Contributor role to the Managed Identity:  
  - Go to your target VM Resource Group
  - Select **Access control (IAM)** from the left menu
  - Click **Add** \>**Add role assignment**
  - Select **Contributor** as the role
  - In the **Assign access to** dropdown, choose**Managed Identity**
  - Select **Automation Account** in the next dropdown
  - Choose your Automation Account from the list
  - Click **Review + assign** to complete the assignment

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/69a8a591202f0727c8ea92697c8dca73.png)

### 2\. Required Module Configuration

Navigate to your newly created Automation Account and import these essential modules:

- Az.Compute
- Az.Accounts

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/adec7a0fd445fcfd3d0488bf365a244a.png)

To import modules:

1. Go to **Shared Resources** →**Modules**
2. Search for each module
3. Import if not already present

### 3\. Creating Automation Runbooks

#### Shutdown Runbook

1. Navigate to **Process Automation** →**Runbooks** →**Create a runbook**
2. Configure the runbook:  
  - **Name**: `Shutdown-VM`
  - **Runbook type**: PowerShell
  - Click **Create**

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/db1356f2df612d14aed2e0414a6013e8.png)

1. Use the following PowerShell script in the editor:

```powershell
param(
    [string]$resourceGroupName = "YourResourceGroupName",
    [string]$vmName = "YourVirtualMachineName"
)

# Authenticate to Azure
Connect-AzAccount -Identity

# Stop the VM
Stop-AzVM -ResourceGroupName $resourceGroupName -Name $vmName -Force

```

*Note: Remember to replace placeholder values (like YourResourceGroupName and YourVirtualMachineName) with your actual Azure resource information before implementing the solution.*  
4\. Click Save and then Publish the runbook

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/104240b576f4dce01acf02b322587f27.png)

#### Startup Runbook

1. Create another runbook:  
  - **Runbook type**: PowerShell
  - Click **Create**

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/9d712fc04d7de4aaae54fb7766fac07d.png)

1. Use the following PowerShell script in the editor:

```powershell
param(
    [string]$resourceGroupName = "YourResourceGroupName",
    [string]$vmName = "YourVirtualMachineName"
)

# Authenticate to Azure
Connect-AzAccount -Identity

# Start the VM
Start-AzVM -ResourceGroupName $resourceGroupName -Name $vmName

```

*Note: Remember to replace placeholder values (like YourResourceGroupName and YourVirtualMachineName) with your actual Azure resource information before implementing the solution.*  
4\. Click Save and then Publish the runbook

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/bbd16e8e097ad635dfe02d3fb9e074f3.png)

### 4\. Scheduling the Runbooks

#### Shutdown Schedule (10:00 PM)

1. Open the `Shutdown-VM` runbook
2. Select "Schedules" and "Select Add a schedule"

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/53efb7e52d15a79aa3ae8b3a5737f702.png)

1. Select **Link a schedule to your runbook**

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/e30f7e04ec869750f9dc479bd1006532.png)

1. Configure schedule:  
  - **Name**: DailyShutdown
  - **Recurrence**: Recurring
  - **Recur every**: 1 day
  - **Start time**: 10:00 PM

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/69704df26dd5a030aab3365c40eb6165.png)

#### Startup Schedule (6:00 AM)

1. Open the `Startup-VM` runbook
2. Select **Link a schedule to your runbook**
3. Configure schedule:  
  - **Name**: DailyStartup
  - **Recurrence**: Recurring
  - **Recur every**: 1 day
  - **Start time**: 6:00 AM

## Testing the Configuration

### 1\. Test the Shutdown Runbook

1. Navigate to your Automation Account
2. Go to **Runbooks** under Process Automation
3. Select the `Shutdown-VM` runbook
4. Click **Start** to open the runbook execution pane
5. Enter the required parameters:  
  - Resource Group Name: `YourResourceGroupName`
  - VM Name: `YourVirtualMachineName`
6. Click **OK** to start the runbook

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/5d97c3eb68afb3ad299cd617c39d1b71.png)

1. Monitor the job output in real-time:  
  - Watch for successful authentication
  - Check for VM status changes
  - Verify completion message

![](https://blog.viveknet.com/content/images/wiki/automating-azure-vm-shutdown-and-startup/57cbcefeb4d2c9f52c8bfe6059d87b3f.png)

1. Validate in Azure Portal:  
  - Navigate to the Virtual Machine
  - Confirm status shows "Stopped (deallocated)"
  - Check the Activity Log for shutdown action

### 2\. Test the Startup Runbook

1. Navigate to your Automation Account
2. Go to **Runbooks** under Process Automation
3. Select the `Startup-VM` runbook
4. Click **Start** to open the runbook execution pane
5. Enter the required parameters:  
  - Resource Group Name: `YourResourceGroupName`
  - VM Name: `YourVirtualMachineName`
6. Click **OK** to start the runbook
7. Monitor the job output in real-time:  
  - Watch for successful authentication
  - Check for VM status changes
  - Verify completion message
8. Validate in Azure Portal:  
  - Navigate to the Virtual Machine
  - Confirm status shows "Running"
  - Check the Activity Log for startup action

## Best Practices

- Always test runbooks during non-production hours
- Monitor the first few scheduled executions
- Keep resource group names and VM names updated in runbook parameters
- Regularly check automation account logs for any failures

## Cost Benefits

Implementing this solution can lead to significant cost savings:

- Assuming a VM costs $100/day when running 24/7
- Running only 8 hours/day (6 AM - 10 PM) reduces runtime by 66%
- Potential monthly savings: \~$2,000 per VM
- Additional savings from reduced network, storage I/O costs

## Alternative Approaches Considered

1. **Windows Task Scheduler**

  - Pros: Simple to implement
  - Cons: Requires dedicated server, no HA, limited monitoring
2. **Azure DevOps Pipelines**

  - Pros: Familiar for DevOps teams
  - Cons: More complex setup, potential cost implications
3. **Azure Functions**

  - Pros: Serverless, cost-effective
  - Cons: More complex to maintain, requires additional setup

## Conclusion

Azure Automation Account provides an enterprise-grade solution for VM scheduling that is reliable, maintainable and cost-effective. The implementation is straightforward and can be easily adapted to manage multiple VMs across different resource groups and subscriptions.