PowerShell: Export to CSV

This will be the beginning of a series of PowerShell Command Posts 🙂

PowerShell is often used to apply commands to several Objects without having to to the same shit over and over again.

So the first we should learn is to Export to CSV file, leveraging Get-MSolUser, which will give us a list of users we can do stuff with:

Example: Get-MsolUser -DomainName yourdomain.com

Combine it With Export CSV:
Example: Get-MsolUser -DomainName yourdomain.com | Export-CSV C:AteaUsers.csv

The result will be a CSV File include all users at your domain.

But you might not want every attribute stored for the users, so we can add a little to just select certain attributes:
Example: Get-MsolUser -DomainName yourdomain.com | Select UserPrincipalName | Export-CSV C:AteaUsers.csv

So this command will only output the UserPrincipalName, which often is enough to turn it around and do a bulk change on all the users.

3 responses to “PowerShell: Export to CSV”

  1. […] you read my article about Export-CSV we have a CSV with all our UserPrincipalNames or you can specify what to Select inside a […]

  2. […] Import-CSV File (See Export-CSV File) Example2: Get-MsolUser -DomainName […]

Leave a Reply


I am Roy Apalnes, a Microsoft Cloud Evangelist working av Sopra Steria. Main focus in Microsoft Security and Endpoint Management, with a bigger picture in mind.

Featured Posts