Serverless and Automation for Administrators: Azure Functions, Logic Apps, Automation Accounts and Scheduled Operations
Why Automate?
- Remove repeated manual work and mistakes
- Stop dev VMs at night, clean old resources, react to alerts, onboard users
Tool Choices
| Tool | Best for |
|---|---|
| Azure Functions | Small pieces of code triggered by timers, HTTP, queues, blobs and more |
| Logic Apps | Low-code workflows with connectors (email, Teams, SharePoint, SQL) |
| Azure Automation | PowerShell or Python runbooks, update management and configuration |
| Event Grid | React to Azure events, such as a resource created |
Azure Functions
- A function runs when a trigger fires (timer, HTTP, blob created, queue message)
- Plans: Consumption or Flex Consumption (pay per execution), Premium (no cold start, VNet) and Dedicated (App Service plan)
- Needs a storage account and optionally Application Insights
bash
az storage account create -g rg-auto -n stfunc482 --sku Standard_LRS
az functionapp create -g rg-auto -n func-admin-482 --storage-account stfunc482 --consumption-plan-location centralindia \
--runtime python --runtime-version 3.11 --functions-version 4 --os-type Linux --assign-identity [system]
python
import logging, azure.functions as func
app = func.FunctionApp()
@app.timer_trigger(schedule="0 0 20 * * 1-5", arg_name="t", run_on_startup=False) # 20:00 on weekdays
def stop_dev_vms(t: func.TimerRequest) -> None:
logging.info("Stopping dev VMs")
# use azure-mgmt-compute with DefaultAzureCredential to deallocate VMs tagged Environment=Dev
Give the function's managed identity the Virtual Machine Contributor role on the dev resource group, so it can stop VMs without secrets.
Logic Apps
- Pick a trigger (for example: when an email arrives, when a blob is created, every day)
- Add actions (send Teams message, create a ticket, call an API) with conditions and loops
- Consumption (pay per run) or Standard (fixed hosting with VNet integration)
Azure Automation
- Create an Automation account with a system-assigned managed identity
- Give that identity a role (for example VM Contributor)
- Create a runbook (PowerShell) and test it
- Link a schedule to run it
powershell
# Runbook: stop all VMs tagged AutoStop=true
Connect-AzAccount -Identity
Get-AzVM -Status | Where-Object { $_.Tags["AutoStop"] -eq "true" -and $_.PowerState -eq "VM running" } |
ForEach-Object { Stop-AzVM -ResourceGroupName $_.ResourceGroupName -Name $_.Name -Force }
- Also: Update management, State configuration, Hybrid Runbook Workers for on-premises servers
- Simple VM auto-shutdown is also available in the VM settings
Practice
- Create a timer-triggered function that logs a message
- Build a Logic App that emails you when a blob is uploaded
- Create an Automation runbook that starts VMs by tag
- Give the identity only the role it needs
Conclusion
Use Functions for code, Logic Apps for low-code flows and Automation runbooks for admin scripts, all with managed identities and least privilege roles.
Quick Summary: why; tools; Functions; Logic Apps; Automation; practice.

