The Export-Csv cmdlet in PowerShell is used to export structured data—such as user details, reports, or object properties—into a CSV (Comma-Separated Values) file. This is especially useful when administrators want to analyze Microsoft 365 data, share results, or archive records for compliance and auditing.
CSV files are lightweight, widely supported, and easy to open in Excel or other spreadsheet tools, making them ideal for reporting and data exchange.
The Export-Csv cmdlet takes a collection of PowerShell objects and converts them into a properly formatted .csv file. It uses the pipeline (|) to accept input and writes each object’s properties as rows and columns.
Syntax:
$data | Export-Csv -Path "output.csv" -NoTypeInformation
You can export users, licenses, groups, and any other data fetched from Microsoft Graph or local PowerShell commands using this method.
Here’s a Microsoft 365 script that fetches all users using Get-MgUser and exports their key details to a CSV file:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
# Get all users with selected properties
$users = Get-MgUser -All -Property DisplayName, UserPrincipalName, Mail
# Select relevant fields for export
$exportData = $users | Select-Object DisplayName, UserPrincipalName, Mail
# Export to CSV
$exportData | Export-Csv -Path "M365Users.csv" -NoTypeInformation
Write-Host "✅ Export complete: M365Users.csv"
Explanation:
This technique is essential for admins who want to document tenant data or generate quick reports.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex