Scheduling Reboot for Azure Virtual Machines using Automation Account
Mohamed Hussien
Cloud Solutions Architect | Enterprise Mobility & Security | Microsoft 365 | 5x Azure | Infrastructure Lead | System Administrator | Technical Support
This documentation offers a comprehensive guide with step-by-step instructions on leveraging an Azure Automation Account to schedule reboots for your Azure Virtual Machines (VMs). The automation of reboots is crucial for maintaining the health and ensuring the timely updates of your VMs. Since Microsoft's Azure platform doesn't offer native options for scheduled reboots, we employ the use of Runbooks and Automation Accounts as an effective workaround..
Prerequisites
Before you begin, make sure you have the following prerequisites:
Step by Step:
1.2 Choose the Managed Identity as 'System assigned'.
1.3 Depending on your network configuration, you can opt for 'Public network' if you require public access, or choose 'Private access' if you need to access resources privately. Afterward, select the appropriate Virtual Network (VNet).
1.4 Select Create.
1.5 After creating the Automation account, navigate to the 'Identity' section in the left pane.
1.6 Next, select 'Azure Role Assignment,' and within the assignment configuration, choose the 'Scope' as 'Subscription.' For 'Subscription,' select the subscription where your VMs are located, and assign the 'Contributor' role.
1.7 Access the Automation account you've created, and in the left pane, click on 'Runbook.' Then, proceed to select 'Create a runbook.'
1.8 Specify your desired name, and under the 'Runbook type' dropdown menu, choose 'PowerShell Workflow' and then Create.
1.7 Access the newly created Runbook, and select 'Edit.' Then, opt for 'Edit in Portal.'
领英推荐
1.8 Here's the modified code that you can copy and paste into your runbook after replacing the placeholders for the resource group name and VM name. You can repeat the line for each VM you want to restart:
workflow demo-reboot-runbook
{
InlineScript
{
Connect-AzAccount -Identity
Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM1 name"
Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM2 name"
Restart-AzVM -ResourceGroupName "Resource Group name" -Name "VM3 name"
# Add more lines as needed for additional VMs
}
}
1.9 You can now initiate a test of the Runbook by clicking on the 'Test Pane' and waiting for the code to finish execution.
2.2 Alternatively, you can opt for 'Recurring' and then specify the desired interval by selecting the preferred day and time.
2.3 Next, we'll link the schedule to our Runbook. To do this, navigate to the Runbook, and in the left pane, select 'Schedules.
2.4 Choose 'Link a schedule to your runbook,' leave the second option unchanged, and proceed to click 'Create.
2.5
2.6 or the final step, you can verify the behavior by checking the VM's activity log, as illustrated below.
Thank you for completing the article. If you have any questions or need further assistance, please feel free to reach me at the contact number provided in my signature.
Best regards,
Mohamed Hussien Rabea
Sr. Microsoft Consultant
+201023113355
Team Leader – System Administration at International Accreditation New Zealand
5 个月Hi Mohammad. Is there a way to reboot an azure connected machine? I have an on prem windows server and I would like to schedule a reboot for it. Thanks.
Cloud Architect | Enterprise Landing Zone | Workload Migration | SRE | Infrastructure Automation
1 年Hello. I read your article. Its well explained. I'm working on similar automation solution. Even, I hard-coded the inputs in few of the solutions. But, have you tried passing multiple resource group or subscriptions input via parameters? I would love to get your input on the same.
Founder of Tosn Courses and trainer on Udemy
1 年???????? ????? ????? ????
Modern Workplace Specialist at Microsoft
1 年Well done rabea
??? Engineer & Manufacturer ?? | Internet Bonding routers to Video Servers | Network equipment production | ISP Independent IP address provider | Customized Packet level Encryption & Security ?? | On-premises Cloud ?
1 年Your article on scheduling VM reboots in Azure using Runbooks and Automation Accounts is a valuable resource for Azure administrators. I appreciate the step-by-step guide you've provided, which makes it accessible even for those less experienced in Azure automation.I'm intrigued by the potential scalability of this approach. Could you shed light on how this method handles a large number of VMs efficiently? Are there any considerations for managing hundreds or thousands of VMs with scheduled reboots to avoid overloading the system or causing disruptions?Additionally, when it comes to the activity log verification, are there specific patterns or indicators administrators should look for to ensure that the reboots have been executed as intended without any hiccups?