Microsoft 365 Analyzer Tool
<# .SYNOPSIS Microsoft 365 Analyzer Tool .DESCRIPTION This script analyzes various aspects of a Microsoft 365 environment, including user accounts, licenses, Exchange Online, SharePoint Online, and Teams. .NOTES File Name : Microsoft365Analyzer.ps1 Author : [Your Name] Prerequisite : PowerShell V5.1 or later, Microsoft 365 PowerShell modules, and appropriate admin permissions Version : 1.0 Date : [Current Date] .EXAMPLE .\Microsoft365Analyzer.ps1 #> # Check and install required modules $requiredModules = @("MSOnline", "ExchangeOnlineManagement", "Microsoft.Online.SharePoint.PowerShell", "MicrosoftTeams") foreach ($module in $requiredModules) { if (!(Get-Module -ListAvailable -Name $module)) { Write-Host "Installing $module module..." -ForegroundColor Yellow Install-Module -Name $module -Force -AllowClobber } } # Import required modules Import-Module MSOnline Import-Module ExchangeOnlineManagement Import-Module Microsoft.Online.SharePoint.PowerShell Import-Module MicrosoftTeams # Global variables $global:reportPath = "$env:USERPROFILE\Desktop\Microsoft365_Analysis_Report_$(Get-Date -Format 'yyyyMMdd_HHmmss').html" <# .SYNOPSIS Displays the main menu of the tool. #> function Show-Menu { Clear-Host Write-Host "=== Microsoft 365 Analyzer Tool ===" -ForegroundColor Cyan Write-Host "1. Analyze User Accounts and Licenses" Write-Host "2. Check Exchange Online Configuration" Write-Host "3. Analyze SharePoint Online Usage" Write-Host "4. Review Teams Configuration" Write-Host "5. Check Security and Compliance Settings" Write-Host "6. Analyze Azure AD Configuration" Write-Host "7. Generate Comprehensive HTML Report" Write-Host "8. Exit" } <# .SYNOPSIS Connects to Microsoft 365 services. #> function Connect-Microsoft365Services { Write-Host "Connecting to Microsoft 365 services..." -ForegroundColor Yellow Connect-MsolService Connect-ExchangeOnline $orgName = (Get-MsolCompanyInformation).DisplayName $adminSiteUrl = "https://$($orgName.Replace(' ', ''))-admin.sharepoint.com" Connect-SPOService -Url $adminSiteUrl Connect-MicrosoftTeams } <# .SYNOPSIS Analyzes user accounts and licenses. .OUTPUTS PSObject containing user account and license analysis. #> function Analyze-UserAccountsAndLicenses { Write-Host "`nAnalyzing User Accounts and Licenses..." -ForegroundColor Yellow $users = Get-MsolUser -All $licenses = Get-MsolAccountSku $analysis = [PSCustomObject]@{ TotalUsers = $users.Count LicensedUsers = ($users | Where-Object {$_.IsLicensed -eq $true}).Count UnlicensedUsers = ($users | Where-Object {$_.IsLicensed -eq $false}).Count BlockedUsers = ($users | Where-Object {$_.BlockCredential -eq $true}).Count LicenseTypes = $licenses | Select-Object AccountSkuId, ActiveUnits, ConsumedUnits } $analysis | Format-List return $analysis } <# .SYNOPSIS Checks Exchange Online configuration. .OUTPUTS PSObject containing Exchange Online configuration details. #> function Check-ExchangeOnlineConfiguration { Write-Host "`nChecking Exchange Online Configuration..." -ForegroundColor Yellow $mailboxes = Get-Mailbox -ResultSize Unlimited $transportRules = Get-TransportRule $exchangeConfig = [PSCustomObject]@{ TotalMailboxes = $mailboxes.Count SharedMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox"}).Count ResourceMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq "RoomMailbox" -or $_.RecipientTypeDetails -eq "EquipmentMailbox"}).Count TransportRules = $transportRules.Count } $exchangeConfig | Format-List return $exchangeConfig } <# .SYNOPSIS Analyzes SharePoint Online usage. .OUTPUTS PSObject containing SharePoint Online usage details. #> function Analyze-SharePointOnlineUsage { Write-Host "`nAnalyzing SharePoint Online Usage..." -ForegroundColor Yellow $sites = Get-SPOSite -Limit All $oneDriveUsage = Get-SPOTenantOneDriveUsageReport $spUsage = [PSCustomObject]@{ TotalSites = $sites.Count TotalStorage = [math]::Round(($sites | Measure-Object StorageUsageCurrent -Sum).Sum / 1024, 2) AverageStoragePerSite = [math]::Round(($sites | Measure-Object StorageUsageCurrent -Average).Average / 1024, 2) OneDriveUsage = $oneDriveUsage } $spUsage | Format-List return $spUsage } <# .SYNOPSIS Reviews Teams configuration. .OUTPUTS PSObject containing Teams configuration details. #> function Review-TeamsConfiguration { Write-Host "`nReviewing Teams Configuration..." -ForegroundColor Yellow $teams = Get-Team $policies = Get-CsTeamsClientConfiguration $teamsConfig = [PSCustomObject]@{ TotalTeams = $teams.Count PublicTeams = ($teams | Where-Object {$_.Visibility -eq "Public"}).Count PrivateTeams = ($teams | Where-Object {$_.Visibility -eq "Private"}).Count AllowEmailIntoChannel = $policies.AllowEmailIntoChannel AllowGiphy = $policies.AllowGiphy AllowStickers = $policies.AllowStickers AllowUserEditMessages = $policies.AllowUserEditMessages } $teamsConfig | Format-List return $teamsConfig } <# .SYNOPSIS Checks security and compliance settings. .OUTPUTS PSObject containing security and compliance settings. #> function Check-SecurityAndComplianceSettings { Write-Host "`nChecking Security and Compliance Settings..." -ForegroundColor Yellow $mfaStatus = Get-MsolUser -All | Where-Object {$_.StrongAuthenticationRequirements.State} $alertPolicies = Get-ProtectionAlert $securitySettings = [PSCustomObject]@{ MFAEnabledUsers = $mfaStatus.Count AlertPolicies = $alertPolicies.Count } $securitySettings | Format-List return $securitySettings } <# .SYNOPSIS Analyzes Azure AD configuration. .OUTPUTS PSObject containing Azure AD configuration details. #> function Analyze-AzureADConfiguration { Write-Host "`nAnalyzing Azure AD Configuration..." -ForegroundColor Yellow $domains = Get-MsolDomain $devices = Get-MsolDevice -All $azureADConfig = [PSCustomObject]@{ TotalDomains = $domains.Count VerifiedDomains = ($domains | Where-Object {$_.Status -eq "Verified"}).Count TotalDevices = $devices.Count AzureADJoinedDevices = ($devices | Where-Object {$_.DeviceTrustType -eq "Azure AD Joined"}).Count } $azureADConfig | Format-List return $azureADConfig } <# .SYNOPSIS Generates a comprehensive HTML report of all analyses. .PARAMETER AllResults Hashtable containing all analysis results. .OUTPUTS Saves an HTML report to the desktop. #> function Generate-HTMLReport { param([hashtable]$AllResults) Write-Host "`nGenerating Comprehensive HTML Report..." -ForegroundColor Yellow $reportContent = @" <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Microsoft 365 Analysis Report</title> <style> body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; } h1, h2, h3 { color: #0078D4; } table { border-collapse: collapse; width: 100%; margin-bottom: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <h1>Microsoft 365 Analysis Report</h1> <p>Generated on: $(Get-Date)</p> <h2>User Accounts and Licenses</h2> $($AllResults.UserAccountsAndLicenses | ConvertTo-Html -Fragment) <h2>Exchange Online Configuration</h2> $($AllResults.ExchangeOnlineConfig | ConvertTo-Html -Fragment) <h2>SharePoint Online Usage</h2> $($AllResults.SharePointOnlineUsage | ConvertTo-Html -Fragment) <h2>Teams Configuration</h2> $($AllResults.TeamsConfig | ConvertTo-Html -Fragment) <h2>Security and Compliance Settings</h2> $($AllResults.SecuritySettings | ConvertTo-Html -Fragment) <h2>Azure AD Configuration</h2> $($AllResults.AzureADConfig | ConvertTo-Html -Fragment) </body> </html> "@ $reportContent | Out-File -FilePath $global:reportPath Write-Host "Report generated and saved to: $global:reportPath" -ForegroundColor Green } # Main program loop Connect-Microsoft365Services $allResults = @{} do { Show-Menu $choice = Read-Host "`nEnter your choice (1-8)" switch ($choice) { "1" { $allResults.UserAccountsAndLicenses = Analyze-UserAccountsAndLicenses } "2" { $allResults.ExchangeOnlineConfig = Check-ExchangeOnlineConfiguration } "3" { $allResults.SharePointOnlineUsage = Analyze-SharePointOnlineUsage } "4" { $allResults.TeamsConfig = Review-TeamsConfiguration } "5" { $allResults.SecuritySettings = Check-SecurityAndComplianceSettings } "6" { $allResults.AzureADConfig = Analyze-AzureADConfiguration } "7" { Generate-HTMLReport -AllResults $allResults } "8" { Write-Host "Exiting program..." -ForegroundColor Yellow; break } default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red } } if ($choice -ne "8") { Read-Host "`nPress Enter to continue..." } } while ($choice -ne "8") # Disconnect from services Disconnect-ExchangeOnline -Confirm:$false Disconnect-SPOService Disconnect-MicrosoftTeams
This Microsoft 365 Analyzer Tool includes:
- A menu-driven interface for easy navigation.
- Functions to analyze various aspects of Microsoft 365:
- User accounts and licenses
- Exchange Online configuration
- SharePoint Online usage
- Teams configuration
- Security and compliance settings
- Azure AD configuration
- Automatic installation of required PowerShell modules.
- Connection to necessary Microsoft 365 services.
- A function to generate an HTML report of all collected data.
Key features:
- Comprehensive analysis of Microsoft 365 environment
- Detailed insights into user accounts, licenses, and service configurations
- Security and compliance overview
- Azure AD configuration analysis
- HTML report generation for easy sharing and viewing of results
This tool is particularly useful for:
- Microsoft 365 administrators
- IT professionals managing Microsoft 365 environments
- Security teams auditing Microsoft 365 configurations
- Consultants performing Microsoft 365 health checks
To use this script effectively:
- Run PowerShell as an administrator
- Ensure you have the necessary permissions to access Microsoft 365 services (Global Administrator or appropriate admin roles)
- Have an active internet connection
This script provides a comprehensive overview of a Microsoft 365 environment, making it easier to identify configuration issues, security concerns, or areas for optimization. It can significantly streamline the process of auditing and maintaining Microsoft 365 services in organizations of any size.

Leave a Reply
Want to join the discussion?Feel free to contribute!