🌍 CloudCostChefs Sustainability Tools

Azure Carbon Emissions Data Collector

Professional PowerShell script for collecting Azure carbon emissions data across single or multiple subscriptions. Generate CSV reports optimized for sustainability dashboards with comprehensive error handling and multi-authentication support.

Multi-Subscription Support
CSV Dashboard Export
Enterprise Authentication
Rate Limit Handling

Carbon Data Collection

Retrieve comprehensive carbon emissions data from Azure's Carbon Optimization API with support for all report types and scopes.

Dashboard-Ready Export

Generate CSV files optimized for Power BI, Tableau, and other dashboard tools with proper data formatting and structure.

Enterprise Authentication

Multiple authentication methods including service principals, Azure CLI, and PowerShell contexts for any environment.

Technical Specifications

Built for enterprise environments with comprehensive error handling, rate limiting, and multi-subscription support

Requirements

PowerShell 5.1+
Windows PowerShell or PowerShell Core
Azure Authentication
Azure CLI, PowerShell, or Service Principal
Azure Permissions
Carbon Optimization Reader role
Internet Connectivity
Access to Azure Management API

Key Features

Multi-Subscription Processing
Process single, multiple, or all accessible subscriptions
Concurrent Processing
Configurable parallel execution with rate limiting
Comprehensive Error Handling
Detailed error reporting and troubleshooting guidance
Pagination Support
Retrieve complete datasets with automatic pagination

Supported Report Types

Choose from multiple report formats to match your sustainability reporting needs

Item Details Report

Comprehensive line-item carbon emissions data for detailed analysis and drill-down reporting.

Best for: Detailed analysis

Monthly Summary

Month-over-month carbon emissions trends and summaries for executive reporting.

Best for: Trend analysis

Overall Summary

High-level carbon footprint overview across all subscriptions and time periods.

Best for: Executive dashboards

Top Items Monthly

Identify highest carbon-emitting resources and services by month for optimization targeting.

Best for: Optimization focus

Top Items Summary

Overall ranking of highest carbon-emitting resources across the entire reporting period.

Best for: Priority identification

Custom Date Ranges

Flexible date range selection for any reporting period with automatic data availability validation.

Best for: Custom reporting

Usage Examples

Real-world examples for common carbon data collection scenarios

Basic Single Subscription

Collect carbon emissions data for a single subscription using current Azure CLI authentication:

.\Get-AzureCarbonEmissions.ps1 -SubscriptionId "12345678-1234-1234-1234-123456789012"

All Accessible Subscriptions

Process all subscriptions you have access to with full dataset retrieval:

.\Get-AzureCarbonEmissions.ps1 -AllSubscriptions -GetFullDataset
Performance Warning: This can take 15+ minutes for enterprise tenants with comprehensive data.

Service Principal Authentication

Automated execution using service principal credentials for scheduled reporting:

.Get-AzureCarbonEmissions.ps1 ` -AllSubscriptions ` -TenantId "87654321-4321-4321-4321-210987654321" ` -ClientId "11111111-1111-1111-1111-111111111111" ` -ClientSecret "your-client-secret" ` -StartDate "2024-01-01" ` -EndDate "2024-01-31" ` -ReportType "MonthlySummaryReport" ` -OutputPath "C:\CarbonReports"

Custom Date Range & Report Type

Generate specific report types for custom date ranges with detailed item analysis:

.Get-AzureCarbonEmissions.ps1 ` -SubscriptionIds @("sub1-guid", "sub2-guid", "sub3-guid") ` -StartDate "2024-01-01" ` -EndDate "2024-03-31" ` -ReportType "ItemDetailsReport" ` -MaxConcurrentJobs 3 ` -OutputPath ".Q1-2024-Carbon-Analysis"

Authentication Methods

Flexible authentication options for any environment - from interactive development to automated production

Azure CLI

Perfect for interactive development and testing. Simply run az login first.

Easy setup
Interactive authentication
Multi-tenant support

Service Principal

Ideal for automation, scheduled tasks, and CI/CD pipelines. Provides non-interactive authentication.

Automated execution
Scheduled reporting
CI/CD integration

Azure PowerShell

Fallback option using existing Azure PowerShell context. Great for PowerShell-heavy environments.

PowerShell native
Context reuse
Seamless integration

Performance & Best Practices

Optimize your carbon data collection with these CloudCostChefs recommendations

Performance Optimization

Rate Limiting

Keep MaxConcurrentJobs ≤ 5 to respect Azure API limits. The script includes intelligent rate limiting and retry logic.

-MaxConcurrentJobs 5

Data Availability

Carbon data is typically available 19+ days after month end. Don't expect real-time data - this is for trend analysis and historical reporting.

Large Datasets

ItemDetailsReport with GetFullDataset can return 10,000+ records and take 15+ minutes for enterprise tenants. Use appropriate report types for your needs.

CloudCostChefs Best Practices

Scheduled Reporting

Set up monthly automated runs using service principals. Schedule for the 20th of each month to ensure data availability for the previous month.

Report Type Selection

Use OverallSummaryReport for executive dashboards, MonthlySummaryReport for trend analysis, and ItemDetailsReport only when detailed drill-down is needed.

Error Handling

The script includes comprehensive error handling with detailed troubleshooting guidance. Review error messages carefully - they often indicate permission or service availability issues.

Common Issues & Solutions

Real-world troubleshooting guide for Azure Carbon Optimization API challenges

"Carbon Optimization service not found (404)"

This tenant may not have Carbon Optimization enabled. The service is not available in all Azure regions and tenant configurations.

Solution: Contact your Azure administrator to verify Carbon Optimization service availability for your tenant.

"Access denied (403)"

Missing required permissions. The Carbon Optimization API requires specific RBAC roles.

Solution: Ensure you have the "Carbon Optimization Reader" role assigned at the subscription level.

"No data available for date range"

Carbon data has a significant processing delay. Data is typically available 19+ days after month end.

Solution: Adjust your date range to request data from at least 3 weeks ago. Use historical data for trend analysis.

"Rate limit exceeded (429)"

Azure Carbon API has undocumented rate limits. The script includes automatic retry logic with exponential backoff.

Solution: Reduce MaxConcurrentJobs parameter or wait for automatic retry. Consider processing subscriptions in smaller batches.

Ready to Track Your Azure Carbon Footprint?

Download the Azure Carbon Emissions Data Collection Script and start building comprehensive sustainability dashboards today.

Part of the CloudCostChefs Cloud Optimization Kitchen • Open Source • MIT License