Introduction
Automation is key to managing large Microsoft 365 environments efficiently. Below are common scenarios and code samples to get you started.
PowerShell Example – Granting a License
Connect-MgGraph -Scopes "User.ReadWrite.All"
$UserId = "john.doe@contoso.com"
$License = "contoso:ENTERPRISEPACK"
Add-MgUserLicense -UserId $UserId -AddLicenses @{SkuId = $License}
Microsoft Graph API – Creating a Teams Channel
POST https://graph.microsoft.com/v1.0/teams/{team-id}/channels
Content-Type: application/json
{
"displayName": "Automation Updates",
"description": "Channel for automated notifications"
}
Power Automate – Daily Report Flow
Use the Recurrence trigger, pull usage data via Graph, and send an email summary.
Best Practices
- Store secrets in Azure Key Vault.
- Use least‑privilege permissions.
- Log actions for auditability.
Comments