In this blog post, we will go through the steps to create and start a Runbook using Azure PowerShell.
Azure Automation Runbooks are a powerful tool for automating repetitive tasks, maintenance, and management of your Azure environment. Utilizing Azure PowerShell, you can create, modify, and start Azure Runbooks with ease.
Connect to your Azure account
First, you need to connect to your Azure account using PowerShell. Open your PowerShell terminal and run the following command:
Connect-AzAccount
Follow the prompts to sign in to your Azure account. Once connected, set the context for your subscription using the command:
Select-AzSubscription -SubscriptionId <YourSubscriptionId>
Replace the placeholders with your actual Automation account name, resource group name, and desired Runbook name.
Create Runbook (optional)
You can also create a PowerShell runbook using the following cmdlet.
New-AzAutomationRunbook -AutomationAccountName "<YourAutomationAccountName>" -ResourceGroupName "<YourResourceGroupName>" -Name "<YourRunbookName>" -Type "PowerShell"
Start Runbook
The following PowerShell code will start an existing Azure Automation Runbook.
$Vars # # change details
$AutomationAccountName="automation-account-name"
$rg_name="resourcegroup-name"
$runbookname="runbook-name"
# Start runbook
Start-AzAutomationRunbook -AutomationAccountName $AutomationAccountName `
-Name $runbookname `
-ResourceGroupName $rg_name
# Check status
Get-AzAutomationRunbook -AutomationAccountName $AutomationAccountName -ResourceGroupName $rg_name