What We Built
Ever wonder who's downloading what from your SharePoint sites? Are you tired of playing detective when sensitive files mysteriously "walk away" from your organization? This guide will transform you from a SharePoint storage landlord into a full-fledged digital surveillance expert with a modern twist.
Solution Overview
This modernized solution leverages Azure Storage Static Website hosting to create an interactive web dashboard that visualizes SharePoint download patterns, user behavior, and security insights. We're moving beyond static Excel reports hidden in SharePoint folders to a sleek, real-time dashboard that updates automatically.
Modern Architecture
Perfect for compliance officers who need pretty charts, security teams who love interactive data, and anyone who's ever had to explain download patterns during a Monday morning panic meeting with actual visual evidence instead of spreadsheet rows.
Choose Your Implementation Path
This guide provides two distinct implementation options for SharePoint download monitoring. Choose the approach that best fits your security requirements and technical preferences:
Azure Storage Static Website
Features:
- Interactive web dashboard with Chart.js
- Mobile-responsive design
- Global CDN delivery
- Real-time JSON data feeds
- Lower cost than SharePoint storage
Requirements:
- • Azure Storage Account
- • Read-only SharePoint permissions
- • Azure Automation setup
Best for: Organizations wanting modern dashboards, mobile access, and enterprise-grade hosting.
SharePoint Direct Upload
Features:
- Direct Excel/CSV file upload
- SharePoint native integration
- Familiar Excel experience
- No additional Azure services
Requirements:
- • Sites.Selected permissions setup
- • SharePoint write access
- • Manual file management
Best for: Organizations preferring traditional SharePoint workflows and Excel-based reporting.
💡 Why "Simpler" is in Quotes
While Option 2 seems simpler at first glance, it requires configuring Sites.Selected permissions for each SharePoint site you want to monitor, plus managing file uploads and versioning. Option 1 provides a more scalable, modern solution with better long-term maintenance.
Shared Technology Stack
Both implementation options share the same core monitoring infrastructure. The difference is primarily in how and where the reports are stored and accessed.
Core Technologies
- PowerShell 7.2+
- Microsoft Graph API
- Exchange Online PowerShell
- Certificate-based authentication
Infrastructure Options
- Option 1: Azure Storage + Chart.js
- Option 2: SharePoint + Excel files
- Azure Automation (both options)
- Same monitoring capabilities
What's New in This Version
Prerequisites
Before we dive into this digital surveillance setup with a modern twist, let's make sure you have everything you need. Think of these as the ingredients for your SharePoint monitoring recipe with a dash of Azure Storage magic.
Common Setup Requirements
These steps are required for both implementation options. Complete these first, then proceed to your chosen implementation path.
Step 1: Get Site and Drive ID
First, we need to identify your SharePoint site using Microsoft Graph API:
https://graph.microsoft.com/v1.0/sites/{hostname}:/{server-relative-path-to-site}
Example:
https://graph.microsoft.com/v1.0/sites/mscloudninja.sharepoint.com:/sites/files_to_query
https://graph.microsoft.com/v1.0/sites/{site-id}/drives
💡 Technical Insight: The site ID and drive ID are required for both implementation options to identify which SharePoint sites and document libraries to monitor.
Step 2: Create Self-Signed Certificate
Generate a secure certificate for authentication (required for both options):
certlm
New-SelfSignedCertificate `
-Subject 'CN=SharePointLogs' `
-KeyLength 2048 `
-KeyUsageProperty All `
-KeyAlgorithm 'RSA' `
-HashAlgorithm 'SHA256' `
-Provider 'Microsoft Enhanced RSA and AES Cryptographic Provider' `
-NotAfter (Get-Date).AddYears(10) `
-KeyExportPolicy Exportable
💡 Technical Insight: Self-signed certificates provide secure authentication for service-to-service communication and are required for both Azure Storage and SharePoint upload options.
Step 3: Create Base App Registration
Base Required Permissions (Both Options)
AuditLog.Read.All
- Read audit log dataGroup.Read.All
- Read group informationUser.Read.All
- Read user profilesExchange.ManageAsApp
- Exchange Online access
⚠️ Important: Additional SharePoint permissions will be configured in the implementation-specific sections below based on your chosen option.
Option 1: Azure Storage Static Website Implementation
Modern Dashboard Solution
This option creates an interactive web dashboard hosted on Azure Storage with real-time charts, mobile responsiveness, and global CDN delivery. Follow these additional steps after completing the common setup above.
1A. Create Azure Storage Account with Static Website
$web
(for dashboard files) and data
(for JSON data)
1B. Configure App Registration for Read-Only Access
Add these permissions to your existing app registration for the Azure Storage option:
Additional Permissions for Option 1
Sites.Read.All
- Read SharePoint data (read-only)
🔐 Security Advantage: This option only requires read access to SharePoint since reports are stored in Azure Storage, significantly reducing the security footprint.
1C. Configure Storage Account Access
CORS Configuration
- Allowed origins: * (or your domain)
- Allowed methods: GET, POST
- Allowed headers: *
- Max age: 3600
Access Keys
Copy storage account name and access key for script configuration.
Option 2: SharePoint Direct Upload Implementation
Traditional SharePoint Solution
This option uploads Excel/CSV reports directly to SharePoint document libraries. While it seems simpler, it requires additional permission configuration for each site you want to monitor.
2A. Configure Sites.Selected Permissions
For the SharePoint upload option, replace Sites.Read.All
with Sites.Selected
for enhanced security:
Sites.Selected
permission to your app registration
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Sites.FullControl.All"
# Configure for each SharePoint site you want to monitor
$appId = "your-app-id-here"
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
# Grant the app read/write access to the specific site
$site = Get-MgSite -SiteId "$($siteUrl):"
Grant-MgSitePermission -SiteId $site.Id -Roles "write" -GrantedToIdentities @{
Application = @{
Id = $appId
DisplayName = "SharePoint Download Monitor"
}
}
# Repeat for each site you want to monitor
# Verify the permission was granted
Get-MgSitePermission -SiteId $site.Id
⚠️ Important: You must repeat the permission grant process for every SharePoint site you want to monitor. This is why it's called "simpler" in quotes - it requires more ongoing permission management.
2B. Prepare SharePoint Document Libraries
2C. Script Modifications for SharePoint Upload
The PowerShell script will need these modifications for SharePoint upload instead of Azure Storage:
# Replace Azure Storage upload section with SharePoint upload
# Export to Excel/CSV instead of JSON
$downloadData | Export-Excel -Path "$env:TEMP\SharePoint_Downloads_$(Get-Date -Format 'yyyy-MM-dd').xlsx" -AutoSize
# Upload to SharePoint using Graph API
$uploadUrl = "https://graph.microsoft.com/v1.0/sites/$siteId/drive/root:/Download Reports/SharePoint_Downloads_$(Get-Date -Format 'yyyy-MM-dd').xlsx:/content"
$fileBytes = [System.IO.File]::ReadAllBytes("$env:TEMP\SharePoint_Downloads_$(Get-Date -Format 'yyyy-MM-dd').xlsx")
$headers = @{
'Authorization' = "Bearer $accessToken"
'Content-Type' = 'application/octet-stream'
}
Invoke-RestMethod -Uri $uploadUrl -Method PUT -Body $fileBytes -Headers $headers
PowerShell Script Configuration (Both Options)
The core PowerShell script is the same for both implementation options. The difference is in the output format and storage destination. Here's how to configure the shared components:
Common Script Variables
Update these variables in the PowerShell script regardless of your chosen implementation:
Your Azure AD tenant ID
App registration client ID
Certificate thumbprint
SharePoint site ID from Graph API
Document library drive ID
Option 1: Azure Storage Variables
Azure Storage account name
Storage account access key
Container for JSON data (e.g., "data")
Option 2: SharePoint Upload Variables
Site ID where reports will be uploaded
Drive ID for the reports library
Folder path for report files
Automation Setup (Both Options)
For continuous monitoring, schedule the script to run at regular intervals using any of these methods:
Task Scheduler
Windows built-in scheduler
Azure Automation
Cloud-based scheduling (Recommended)
Azure Functions
Serverless execution
Dashboard Features
Download Tracking
Real-time monitoring of file downloads across all SharePoint sites with detailed user and file information.
Usage Analytics
Interactive charts showing download trends, top files, most active users, and site usage patterns.
Smart Filtering
Advanced filtering by date range, file type, user department, or specific SharePoint sites.
Security Monitoring
Identify unusual download patterns, potential data exfiltration, and access from external users.
Export Options
Export filtered data to CSV, Excel, or PDF formats for compliance reporting and further analysis.
Responsive Design
Mobile-friendly dashboard that works seamlessly on desktop, tablet, and smartphone devices.
Download PowerShell Scripts
Download the appropriate PowerShell script based on your chosen implementation option. Both scripts share the same core monitoring logic but differ in their output and storage mechanisms.
Azure Storage Script
JSON output for modern dashboards
Script Features:
- ✅ Certificate-based authentication
- ✅ JSON data generation for dashboards
- ✅ Azure Storage upload automation
- ✅ Error handling & logging
- ✅ Exchange Online & Graph API integration
Ready for Azure Automation runbooks
SharePoint Upload Script
Excel/CSV output for traditional workflows
Script Features:
- ✅ Certificate-based authentication
- ✅ Excel/CSV file generation
- ✅ SharePoint direct upload
- ✅ Sites.Selected permission support
- ✅ Traditional report formatting
Includes Excel export capabilities
Shared Script Capabilities
Both scripts provide the same comprehensive monitoring and data collection capabilities, optimized for Azure Automation runbooks.
Security
- ✅ Certificate authentication
- ✅ Secure credential management
- ✅ Audit log processing
Reliability
- ✅ Comprehensive error handling
- ✅ Detailed logging
- ✅ Graceful disconnection
Data Processing
- ✅ Statistical analysis
- ✅ User enrichment
- ✅ Time-based filtering
Azure Integration
- ✅ Automation optimized
- ✅ Variable management
- ✅ Service connectivity
Azure Automation Setup
Now comes the fun part - building our digital surveillance system with a modern, interactive twist! Think of Azure Automation as your personal IT assistant that never sleeps, never calls in sick, and creates beautiful dashboards instead of boring Excel files.
1. Prepare the Automation Account
2. Configure Certificates and Variables
Certificate Upload
Required Variables
AppID
- Application client IDCertificateName
- Certificate nameTenantID
- Directory tenant IDStorageAccountName
- Storage accountStorageAccountKey
- Storage key🔐 Security Best Practice: Consider using Azure Key Vault for storing sensitive information like storage account keys and certificate details. This provides enhanced security with proper access controls, audit trails, and supports automatic key rotation scenarios.
3. Create the Modernized Runbook
Download PowerShell Script
Complete Azure Automation runbook (150+ lines)
Script Features:
- ✅ Certificate-based authentication
- ✅ Exchange Online & Graph API integration
- ✅ JSON data generation for dashboards
- ✅ Azure Storage upload automation
- ✅ Error handling & logging
Download Options:
Ready for Azure Automation runbooks
Script Overview & Features
The complete PowerShell script is a comprehensive solution optimized for Azure Automation runbooks with enterprise-grade functionality and modern data output formats.
Security & Authentication
- ✅ Certificate-based authentication
- ✅ Exchange Online connectivity
- ✅ Microsoft Graph API integration
- ✅ Secure credential management
Data Processing & Storage
- ✅ Audit log processing
- ✅ JSON data generation
- ✅ Azure Storage upload automation
- ✅ Historical data archiving
Reliability & Monitoring
- ✅ Comprehensive error handling
- ✅ Detailed logging & output
- ✅ Graceful service disconnection
- ✅ Azure Automation optimized
Modern Dashboard Output
- ✅ Real-time JSON data feeds
- ✅ Statistical analysis
- ✅ Empty data fallback handling
- ✅ Web-optimized format
Option 1: Interactive Dashboard Files
Azure Storage Dashboard Components
This section applies only to Option 1 (Azure Storage). If you chose Option 2 (SharePoint upload), you'll work with traditional Excel/CSV files instead of these web dashboard components.
Modern Dashboard Solution
The interactive dashboard provides real-time visualization of SharePoint download activity with modern responsive design, dark mode support, and advanced Chart.js visualizations.
Real-time Visualization
Dynamic charts and graphs that update automatically with fresh data
Responsive Design
Perfect viewing experience on desktop, tablet, and mobile devices
Dark Mode Support
Automatic theme switching with full dark mode compatibility
Download Dashboard Files
Complete interactive dashboard solution for Azure Storage hosting
Dashboard Features:
- ✅ Real-time data visualization with Chart.js
- ✅ Interactive filtering and search
- ✅ Dark/light theme support
- ✅ Responsive mobile-friendly design
- ✅ Automatic data refresh
- ✅ Export and sharing capabilities
- ✅ Performance optimized
- ✅ Cross-browser compatibility
Dashboard Deployment to Azure Storage
Deploy your interactive dashboard to Azure Storage static website hosting:
$web
container:
- •
index.html
(rename dashboard.html to index.html) - •
dashboard.css
- •
dashboard.js
Option 2: SharePoint Report Files
Traditional Excel/CSV Reports
This section applies only to Option 2 (SharePoint upload). With this approach, the PowerShell script generates Excel or CSV files that are uploaded directly to SharePoint document libraries for traditional file-based access.
Excel Report Features
- ✅ Familiar Excel interface
- ✅ Advanced filtering and sorting
- ✅ Pivot table capabilities
- ✅ Print-friendly formatting
- ✅ Offline accessibility
- ✅ SharePoint integration
SharePoint Integration
- ✅ Direct library upload
- ✅ Version history tracking
- ✅ SharePoint permissions
- ✅ Mobile SharePoint app access
- ✅ Email notifications
- ✅ Workflow integration
Report Configuration Options
The SharePoint upload script can generate reports in multiple formats based on your requirements:
Excel (.xlsx)
Rich formatting with charts, conditional formatting, and multiple worksheets
CSV (.csv)
Lightweight format for data analysis and import into other systems
PDF Reports
Fixed-format reports for executive summaries and compliance documentation
Implementation Considerations
Advantages
- • No additional Azure Storage costs
- • Familiar SharePoint interface
- • Native Office 365 integration
- • Existing SharePoint security model
Considerations
- • Requires Sites.Selected configuration for each site
- • Manual file management and versioning
- • No real-time dashboard visualization
- • Limited mobile experience compared to web dashboard
Modern Solution Benefits
The modernized solution provides significant advantages over the traditional Excel-to-SharePoint approach:
Cost Efficiency
- Lower Storage Costs: Azure Storage is significantly cheaper than SharePoint storage
- No SharePoint Licensing: Reduces dependency on SharePoint Online licenses for report hosting
- CDN Integration: Global content delivery through Azure CDN for improved performance
Performance & Scalability
- Faster Loading: JSON data loads much faster than Excel files
- Real-time Updates: Dashboard refreshes automatically without manual intervention
- Global Accessibility: Static website hosting provides worldwide accessibility
- Mobile Optimized: Responsive design works seamlessly on all devices
Enhanced User Experience
- Interactive Visualizations: Charts and graphs provide immediate insights
- Advanced Filtering: Real-time filtering capabilities for data exploration
- Dark Mode Support: Modern UI with theme preferences
- No Software Dependencies: Works in any modern web browser
Security & Compliance
- Reduced Attack Surface: No SharePoint write permissions required
- Data Isolation: Monitoring data stored separately from source systems
- Access Control: Fine-grained access control through Azure Storage policies
- Audit Trail: Complete audit trail of data access and modifications
Script Architecture and Technical Deep Dive
Authentication Flow
The automation script uses certificate-based authentication to establish secure connections with Microsoft Graph and Exchange Online. Here's what happens under the hood:
Data Processing Pipeline
The script implements a sophisticated data processing pipeline:
- Event Filtering: Filters audit log events to focus on SharePoint file download activities
- Data Enrichment: Enhances raw audit data with user and site information
- JSON Generation: Creates structured JSON data for dashboard consumption
- Azure Storage Upload: Uploads the generated data to Azure Storage for dashboard access
Error Handling and Resilience
Production-ready automation requires robust error handling:
# Example error handling pattern
try {
$auditData = Search-UnifiedAuditLog -StartDate $startDate -EndDate $endDate -Operations FileDownloaded
Write-Output "Retrieved $($auditData.Count) audit records"
}
catch {
Write-Error "Failed to retrieve audit data: $($_.Exception.Message)"
# Implement fallback logic or notification here
}
Advanced Configuration Options
Custom Filtering and Alerting
Enhance your monitoring with custom filters and real-time alerting capabilities:
Content-Based Filtering
- File Type Filtering: Monitor specific file types (.docx, .pdf, .xlsx)
- Size Thresholds: Alert on downloads of large files
- Sensitive Content: Flag downloads containing keywords
Behavioral Monitoring
- User-based Alerts: Notifications for specific users or groups
- Volume Thresholds: Alert when downloads exceed normal patterns
- Time-based Rules: Flag downloads outside business hours
Integration with Microsoft Sentinel
For enterprise environments, integrate with Microsoft Sentinel for advanced security analytics and threat detection:
# Example Log Analytics workspace integration
$workspaceId = "your-workspace-id"
$sharedKey = "your-shared-key"
# Send custom log data to Sentinel
$logData = @{
TimeGenerated = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
DownloadEvent = $downloadDetails
RiskScore = $calculatedRiskScore
}
Send-LogAnalyticsData -WorkspaceId $workspaceId -SharedKey $sharedKey -Body $logData
🛡️ Security Enhancement: Sentinel integration enables AI-powered threat detection, advanced hunting queries, and automated incident response for SharePoint download monitoring.
Monitoring and Maintenance
Runbook Health Monitoring
Keep your automation running smoothly with comprehensive monitoring:
Execution Monitoring
- Execution History: Review logs in Azure portal
- Performance Metrics: Monitor duration and resource usage
- Error Alerting: Azure Monitor alerts for failures
Credential Management
- Certificate Expiration: Track renewal requirements
- Permission Audits: Regular access reviews
- Security Monitoring: Unauthorized access detection
Scaling Considerations
As your monitoring requirements grow, implement these scaling strategies:
Split large audit log queries across multiple runbooks
Implement checkpoints to avoid reprocessing data
Implement retention policies for older reports
Use Graph API batching for multiple site queries
Troubleshooting Common Issues
Authentication Problems
Certificate Issues
Verify certificate validity and proper upload to Azure Automation. Check expiration dates and ensure the certificate has the required permissions.
Permission Errors
Ensure all required API permissions are granted and admin consented. Review Sites.ReadWrite.All or Sites.Selected configurations.
Tenant Configuration
Check that audit logging is enabled in your Office 365 tenant and that the audit log retention meets your requirements.
Performance Issues
Query Timeouts
Reduce date ranges or implement pagination for large datasets
Rate Limiting
Implement backoff strategies for Graph API throttling
Memory Usage
Process data in chunks to avoid memory exhaustion
Data Quality Issues
Missing Events
Audit log events may have up to 24-hour delay
Incomplete Data
Verify that audit log retention settings meet your requirements
Duplicate Events
Implement deduplication logic for overlapping time ranges
Security and Compliance Considerations
Data Privacy
When implementing download monitoring, consider privacy implications and user rights:
Inform users that download activities are being monitored
Implement appropriate retention policies for audit reports
Restrict access to monitoring reports to authorized personnel only
Consider anonymizing user data in reports where possible
Regulatory Compliance
Ensure your monitoring solution meets regulatory requirements and industry standards:
Legal Compliance
- GDPR Compliance: Implement data subject rights and consent mechanisms
- SOX Compliance: Maintain proper audit trails and access controls
- HIPAA Compliance: Additional security controls for healthcare data
Industry Standards
- ISO 27001: Information security management standards
- NIST Framework: Cybersecurity framework compliance
- Industry Best Practices: Sector-specific requirements
Mission Accomplished!
Congratulations!
You've successfully built a comprehensive, modernized SharePoint download monitoring solution that would make any security team proud!
What You've Achieved
- ✅ Transformed manual Excel reports into automated JSON feeds
- ✅ Created stunning interactive dashboards with Chart.js
- ✅ Implemented enterprise-grade security with certificate authentication
- ✅ Built responsive, mobile-friendly monitoring solution
- ✅ Established modern Azure Storage hosting architecture
The Value You've Created
- ⚡ Real-time data visualization and insights
- 📱 Beautiful dashboards that work on any device
- 🔒 Secure, compliant monitoring solution
- 🚀 Scalable foundation for future enhancements
- 💰 Cost-effective alternative to commercial tools
Your New Reality
"No more downloading Excel files, no more manual refresh cycles, and no more squinting at tiny spreadsheet cells on mobile devices. Your stakeholders now have access to a professional-grade dashboard that updates automatically and works beautifully on any device!"
What's Next?
Ready to take your monitoring to the next level? Consider these powerful enhancements:
Azure Logic Apps
Set up automated alerts for suspicious download patterns
Power BI Integration
Connect your JSON data to Power BI for advanced analytics
Microsoft Sentinel
Forward events to Sentinel for comprehensive security monitoring
Teams Notifications
Send daily/weekly summary reports to Teams channels
Machine Learning
Implement anomaly detection using Azure Cognitive Services
Mobile Apps
Develop mobile dashboards for on-the-go monitoring

About MS Cloud Ninja
Specializing in Microsoft 365, Azure, and modern workplace solutions. Helping organizations leverage cloud technologies for enhanced security, automation, and productivity through practical guides and innovative solutions.