No Search Result

How to use Export-CSV in PowerShell

By Lazy-Fixer・ Published in htmlcssjsJanuary 15, 2025・ 1 min read

With PowerShell, you can extract all kinds of information from services like Active Directory or Microsoft 365. But sometimes you need to process this information further in Excel or another system. To do this we can use the Export-CSV function in PowerShell.

The Export-CSV function converts PowerShell objects into a CSV string and saves them into a CSV file. If you only need a CSV string, then you can also use the ConvertTo-CSV function in PowerShell.

In this article, we are going to take a look at how to use the Export-CSV function, how to prevent common mistakes, and what different options there are that you can use.

PowerShell Export-CSV

The Export-CSV cmdlet is pretty straightforward and only has a few properties that are useful:

  • Path – (Required) Location of the CSV file
  • NoTypeInformation – Removes the Type information header from the output. Not needed any more in PowerShell 6
  • Delimiter – Default is comma, but you can change it
  • Append – Append to an existing CSV file
  • Force – Useful in combination with Append
  • NoClobber – Don’t overwrite existing files
  • UseQuotes – (PowerShell 7 only) wrap values in quotes or not

We are going to start with something simple, exporting our Microsoft 365 users to a CSV file. I am going to use Azure AD throughout the examples here, so if you want to follow along, make sure you connect the Azure AD first.

The Get-AzureADUser cmdlet returns all the users in your Microsoft 365 tenant, as you can see in the screenshot below. What we are going to do is to export this output to a CSV file. To do this we can simply pipe the Export-CSV cmdlet behind it:

Get-AzureADUser | Export-Csv c:\temp\azureadusers.csv -NoTypeInformation