Executive summary: Ship AD-Audit like a product—use CI/CD, proper packaging, and notifications to operate reliably at scale.
Key recommendations:
- Automate tests (Pester) and linting in CI
- Package modules for clean versioned distribution
- Send HTML completion emails to stakeholders
Supporting points:
- Ready-made workflows and templates
- Artifacts and coverage reporting patterns
- Practical triggers and job breakdowns
Version: 2.0.0
Last Updated: October 22, 2025
Author: Adrian Johnson
The M&A Audit Tool now includes enterprise-ready features for professional deployment:
- ✅ CI/CD Integration - Automated testing pipelines
- ✅ PowerShell Module - Professional packaging and distribution
- ✅ Email Notifications - Automated completion alerts with HTML summaries
File: .github/workflows/test.yml
Features:
- Automated Pester test execution on push/PR
- Code coverage reporting (Codecov integration)
- PowerShell Script Analyzer linting
- Test result publishing with detailed reports
- Artifact uploads for test results and coverage
Triggers:
- Push to
mainordevelopbranches - Pull requests to
mainordevelop - Manual workflow dispatch
Workflow Jobs:
- Installs Pester 5.x
- Runs all 110+ tests
- Generates NUnit XML results
- Calculates code coverage (~75%)
- Publishes test results and coverage
- Fails build if tests fail
- Installs PSScriptAnalyzer
- Scans all
.ps1files - Reports errors and warnings
- Fails build on errors
- Aggregates test + lint results
- Reports overall pass/fail
Usage:
# Enable GitHub Actions
# 1. Push .github/workflows/test.yml to repository
# 2. Navigate to Actions tab in GitHub
# 3. Workflows run automatically on push/PR
# View results:
# - https://github.com/your-org/AD-Audit/actionsBadge for README:
File: azure-pipelines.yml
Features:
- Multi-stage pipeline (Test → Package → Notify)
- Pester test execution with NUnit reporting
- Code coverage with JaCoCo format
- PowerShell Script Analyzer integration
- Module packaging for deployment
- Artifact publication
Stages:
-
Job 1 - Pester Tests:
- Runs all tests
- Publishes test results
- Publishes code coverage
- Displays test summary
-
Job 2 - Script Analyzer:
- Lints all PowerShell files
- Reports errors/warnings
- Fails on errors
- Runs only on
mainbranch - Creates module directory structure
- Copies all required files
- Publishes build artifact
- Sends build notifications
- Reports success/failure status
Usage:
# Setup in Azure DevOps:
# 1. Create new pipeline
# 2. Select "Existing Azure Pipelines YAML file"
# 3. Choose /azure-pipelines.yml
# 4. Run pipeline
# View results:
# - Pipelines → Your Pipeline → RunsIntegration with Release Pipeline:
- Trigger releases on successful builds
- Deploy to staging/production
- Automated module distribution
File: AD-Audit.psd1
Module Information:
- Name: AD-Audit
- Version: 2.0.0
- GUID:
8f4e3d2c-1a5b-4c9e-8f3d-2a1b5c9e8f3d - Author: Adrian Johnson
- Description: M&A Technical Discovery Audit Tool
Compatibility:
- PowerShell 5.1+
- PowerShell Core 7.x+
- Windows only (requires AD module)
Dependencies:
ActiveDirectory(Required)Microsoft.Graph(Optional - cloud audit)ExchangeOnlineManagement(Optional)PnP.PowerShell(Optional)MicrosoftTeams(Optional)Microsoft.PowerApps.Administration.PowerShell(Optional)
Exported Functions:
| Function | Purpose |
|---|---|
Start-MAAudit |
Main orchestration |
Invoke-ADAudit |
Active Directory audit |
Invoke-EntraIDAudit |
Entra ID audit |
Invoke-ExchangeAudit |
Exchange Online audit |
Invoke-SharePointTeamsAudit |
SharePoint/Teams audit |
Invoke-PowerPlatformAudit |
Power Platform audit |
Invoke-ComplianceAudit |
Compliance audit |
New-AuditReport |
Generate HTML reports |
Initialize-AuditDatabase |
Create SQLite database |
Invoke-AuditQuery |
Query audit database |
Decrypt-AuditData |
Decrypt audit archives |
# Clone repository
git clone https://github.com/adrian207/AD-Audit.git
cd AD-Audit
# Import module
Import-Module .\AD-Audit.psd1
# Verify
Get-Module AD-Audit# Find module path
$env:PSModulePath -split ';'
# Copy to user module path
$destination = "$HOME\Documents\PowerShell\Modules\AD-Audit"
Copy-Item -Path ".\AD-Audit" -Destination $destination -Recurse
# Import
Import-Module AD-Audit# Install from PowerShell Gallery
Install-Module -Name AD-Audit -Scope CurrentUser
# Import
Import-Module AD-Audit# Import module
Import-Module AD-Audit
# Run audit with notification
Start-MAAudit `
-CompanyName "Acme Corp" `
-OutputFolder "C:\Audits" `
-NotificationEmail "admin@company.com" `
-ServerInventory $true `
-CreateDatabase
# List available commands
Get-Command -Module AD-Audit
# Get help
Get-Help Start-MAAudit -FullAutomatically sends HTML email notification when audit completes.
Function: Send-AuditNotification
Features:
- Modern HTML email with gradient styling
- Audit completion summary with metrics
- Module success/failure breakdown
- Output location and report links
- Next steps checklist
- Data quality score display
# Run audit with email notification
.\Run-M&A-Audit.ps1 `
-CompanyName "Contoso" `
-OutputFolder "C:\Audits" `
-NotificationEmail "admin@contoso.com"# Modify Send-AuditNotification function parameters:
$mailParams = @{
SmtpServer = "smtp.gmail.com" # Change SMTP server
Port = 587 # Change port
UseSsl = $true
}
# Or use environment variables
$env:AUDIT_SMTP_SERVER = "smtp.company.com"
$env:AUDIT_SMTP_PORT = "25"For servers requiring authentication, modify the function to accept credentials:
# In Run-M&A-Audit.ps1, add parameter:
[PSCredential]$SmtpCredential
# Pass to Send-AuditNotification:
Send-AuditNotification `
-ToEmail $NotificationEmail `
-SmtpServer "smtp.office365.com" `
-SmtpPort 587 `
-Credential $SmtpCredentialThe notification email includes:
- Title: "🎉 M&A Audit Complete"
- Subtitle: Company name
- Status Badge: Success/Warning indicator
- Duration: Execution time in minutes
- Modules Completed: Count of successful modules
- Modules Failed: Count of failed modules
- Data Quality: Percentage score (0-100%)
- Successful Modules: ✓ List of completed modules
- Failed Modules: ✗ List of failed modules (if any)
- Output Location: File path to audit results
- Generated Reports: List of HTML reports
- Next Steps: Recommended actions checklist
- Footer: Execution details and timestamp
Professional HTML email with:
- Gradient header (purple/blue)
- Responsive grid layout
- Color-coded status badges (green/yellow/red)
- Modern Segoe UI font family
- Box shadows and border radius
- Hover effects on links
SmtpServer: smtp.office365.com
Port: 587
UseSsl: $true
Requires: Office 365 mailboxSmtpServer: smtp.gmail.com
Port: 587
UseSsl: $true
Requires: App password or OAuthSmtpServer: mail.company.local
Port: 25
UseSsl: $false
Requires: Network access to ExchangeSmtpServer: smtp.sendgrid.net
Port: 587
UseSsl: $true
Requires: SendGrid API keyCheck 1: Verify SMTP settings
Test-NetConnection -ComputerName smtp.office365.com -Port 587Check 2: Authentication
# Test with Send-MailMessage
Send-MailMessage `
-To "test@company.com" `
-From "audit@company.com" `
-Subject "Test" `
-Body "Test" `
-SmtpServer "smtp.office365.com" `
-Port 587 `
-UseSslCheck 3: Firewall/Proxy
- Ensure outbound port 587/25 is open
- Configure proxy if required
Check 4: From Address
# Ensure From address is valid
# Some servers require From to match authenticated account| Issue | Solution |
|---|---|
| "Mailbox unavailable" | Check From address matches authenticated mailbox |
| "Relay access denied" | SMTP server requires authentication |
| "Connection timeout" | Check firewall, port availability |
| "SSL/TLS error" | Verify UseSsl setting matches server requirements |
# 1. Install module
Import-Module AD-Audit
# 2. Run comprehensive audit with all features
Start-MAAudit `
-CompanyName "Merger Target Corp" `
-OutputFolder "D:\Audits" `
-NotificationEmail "cfo@acquirer.com,cto@acquirer.com" `
-ServerInventory $true `
-ServerEventLogDays 30 `
-ServerLogonHistoryDays 90 `
-MaxParallelServers 20 `
-CreateDatabase `
-CreateEncryptedArchive `
-ComplianceFocus "HIPAA,SOX" `
-Verbose
# 3. CI/CD pipeline automatically:
# - Runs tests
# - Validates code quality
# - Publishes artifacts
# 4. Email notification automatically sent to stakeholders
# 5. Review results
Start-Process "D:\Audits\*\index.html"# Trigger audit from ServiceNow workflow
# Parse notification email for status
# Create incident if failures detected# Post notification to Teams channel via webhook
$teamsWebhook = "https://outlook.office.com/webhook/..."
Invoke-RestMethod -Uri $teamsWebhook -Method Post -Body $jsonBody# Import SQLite database to Power BI
# Create executive dashboard
# Schedule refresh after audit runs- ✅ Use encrypted archive for sensitive data
- ✅ Restrict email distribution list
- ✅ Store SMTP credentials securely (Azure Key Vault)
- ✅ Enable EFS encryption on output folder
- ✅ Run tests in CI/CD before deployment
- ✅ Monitor execution time (baseline: 30-90 min)
- ✅ Use parallel processing (10-20 servers)
- ✅ Schedule audits during off-hours
- ✅ Review test results weekly
- ✅ Update module dependencies monthly
- ✅ Archive old audit results (retention: 1 year)
- ✅ Document custom configurations
- ✅ Test in dev environment first
- ✅ Use version control (Git)
- ✅ Document SMTP configuration
- ✅ Create runbook for troubleshooting
- User Guide:
docs/USER_GUIDE.md - Testing Guide:
Tests/TESTING_GUIDE.md - Installation:
docs/INSTALLATION.md - Troubleshooting:
docs/TROUBLESHOOTING.md
- GitHub: https://github.com/adrian207/AD-Audit
- Issues: https://github.com/adrian207/AD-Audit/issues
- Releases: https://github.com/adrian207/AD-Audit/releases
- Author: Adrian Johnson
- Email: adrian207@gmail.com
Ready for enterprise deployment! 🚀