$users = Get-DistributionGroupMember -Identity "ProjectX-Team" $users | ForEach-Object Set-Mailbox -Identity $_.PrimarySmtpAddress -LitigationHoldEnabled $true -LitigationHoldDuration 365 This is the equivalent of a batch file for legal discovery, impossible to do via GUI for 200+ users. 4. Real-Time Monitoring – "Active Office 365 CMD as a Dashboard" You can run a live, updating terminal dashboard using PowerShell loops:

while($true) Clear-Host Write-Host "=== Office 365 Active CMD Monitor ===" -ForegroundColor Cyan Write-Host "Time: $(Get-Date)" $activeUsers = Get-MgUser -All This mimics top or htop but for your tenant. 5.1 Find All Admin Role Assignments (Who can wreck your tenant) Get-MgRoleManagementDirectoryRoleAssignment | Where-Object $_.RoleDefinitionId -eq "Global Administrator" | Select-Object PrincipalId, RoleDefinitionId 5.2 Detect Mailbox Forwarding (Common data exfiltration) Get-Mailbox -ResultSize Unlimited | Where-Object $_.ForwardingSmtpAddress -ne $null | Select-Object DisplayName, ForwardingSmtpAddress, DeliverToMailboxAndForward Interesting finding: Many attackers set DeliverToMailboxAndForward = $true to keep the user unaware. 6. Automation Script – "Office 365 Daily Health Check" Save as O365-Health.ps1 and run daily via Task Scheduler or cron:

# Report summary Write-Output "=== O365 Health Report $(Get-Date) ===" Write-Output "Users: $(Get-MgUser -All).Count" Write-Output "Disabled users: $(Get-MgUser -All | Where-Object $_.AccountEnabled -eq $false).Count" Write-Output "Guest accounts: $(Get-MgUser -All | Where-Object $_.UserType -eq 'Guest').Count" Write-Output "Mailboxes > 90GB: $((Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object $_.TotalItemSize.Value.ToGB() -gt 90).Count)" Though limited, native cmd can still interact with O365 via curl to Graph API with a token:

@echo off curl -X GET "https://graph.microsoft.com/v1.0/users" -H "Authorization: Bearer %ACCESS_TOKEN%" You can get %ACCESS_TOKEN% via az account get-access-token (Azure CLI) or Connect-MgGraph then extract token. | GUI | Active CMD | |-----|-------------| | Slow navigation | Instant execution | | Error-prone clicks | Scriptable, repeatable | | Hidden properties visible only via UI | Full object properties exposed | | Manual audit | Scheduled automation |