# Set .csv to be exported name and path. Ensure the path already exists $thecsv = "c:\scripts\exchange_mailbox.csv" #Add the Exchange Powershell Snapin Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn #Wait 30 seconds for the Exchange Powershell Snapin to finish loading Start-Sleep -Seconds 30 # Grab all the exchange mailboxes e-mail addresses and export them to .csv file and path specified above Get-Mailbox -ResultSize Unlimited | Select-Object PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Export-CSV $thecsv -NoTypeInformation -Encoding UTF8 #Remove all the generated quotes from the generated csv set-content $thecsv ((get-content $thecsv) -replace '"')