Office365: Cmd

$securePassword = ConvertTo-SecureString "client_secret" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("app@client-id", $securePassword) Connect-MgGraph -AccessToken (Get-MsalToken -ClientId "client-id" -TenantId "tenant-id" -ClientSecret "secret").AccessToken | Issue | Fix | |-------|-----| | Connect-ExchangeOnline fails | Run as admin; check TLS: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | | Graph auth errors | Request scopes explicitly: -Scopes "User.Read.All", "Mail.Send" | | Module not recognized | Install-Module -Name ModuleName -Force -AllowClobber | | Slow commands | Use -Top or -PageSize to limit results | 8. Quick Reference Card ┌─────────────────────┬──────────────────────────────────────────┐ │ Task │ Command │ ├─────────────────────┼──────────────────────────────────────────┤ │ Connect Exchange │ Connect-ExchangeOnline │ │ Connect Graph │ Connect-MgGraph │ │ List all users │ Get-MgUser -All │ │ Get user details │ Get-MgUser -UserId "user@domain.com" │ │ List groups │ Get-MgGroup │ │ Assign license │ Set-MgUserLicense │ │ Create user │ New-MgUser -DisplayName "..." ... │ │ Delete user │ Remove-MgUser -UserId "..." │ │ Get mailbox folders │ Get-EXOMailboxFolderStatistics │ │ Teams list │ Get-Team │ │ CLI login │ m365 login │ └─────────────────────┴──────────────────────────────────────────┘ Final Tip For daily admin tasks , use Microsoft Graph PowerShell SDK — it’s the future. For quick one-offs, CLI for Microsoft 365 works directly from CMD without PowerShell.

m365 login m365 status m365 aad user list Get group members m365 aad o365group member list --groupId "group-id" Send email via Graph m365 outlook mail send --to "user@domain.com" --subject "Test" --body "Hello from CLI" 6. One-Liner Scripts (Batch + PowerShell) Save as m365_manage.cmd : office365 cmd

Save this post as a cheat sheet and adapt the commands to your tenant. For quick one-offs, CLI for Microsoft 365 works

# Exchange Online Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All" Teams Connect-MicrosoftTeams 4. Useful Commands (Copy-Paste Ready) Users # Get all users Get-MgUser -All Assign license Set-MgUserLicense -UserId "user@domain.com" -AddLicenses @SkuId = "your_sku_id" -RemoveLicenses @() Block sign-in Update-MgUser -UserId "user@domain.com" -AccountEnabled:$false Groups # List all Microsoft 365 groups Get-MgGroup -Filter "groupTypes/any(c:c eq 'Unified')" Add member Add-MgGroupMember -GroupId "group-id" -DirectoryObjectId "user-id" Mailboxes # Get mailbox stats Get-EXOMailbox -Identity "user@domain.com" | fl Set forwarding Set-EXOMailbox -Identity "user@domain.com" -ForwardingAddress "forward@domain.com" -DeliverToMailboxAndForward $false Licensing # Get available SKUs Get-MgSubscribedSku Assign license Set-MgUserLicense -UserId "user@domain.com" -AddLicenses @SkuId = "e.g., STANDARDWOFFPACK_IW_FACULTY" -RemoveLicenses @() 5. CLI for Microsoft 365 (No PowerShell) Run from standard CMD: Get-MgUser -Top 5 | Format-Table DisplayName

powershell Then connect to Microsoft 365:

@echo off powershell -Command "Connect-MgGraph -Scopes 'User.Read.All'; Get-MgUser -Top 5 | Format-Table DisplayName,UserPrincipalName" pause For unattended scripts (app-only auth):