MSDN Community

Automating Microsoft 365 Tasks

Learn how to streamline your workflow with PowerShell, Graph API, and Power Automate.

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

Comments