Search code examples
powershellcsvexchange-serverexchange-server-2013

How to import multiple mailboxes based on a CSV file?


I have a CSV file with 100+ lines in this format:

\\10.10.10.1\PSTs\DJ10001.pst,John.Doe@example.com

I want to loop through the file and import the PST file to the mailbox.

I understand that I can use Exchange Management Shell to import a PST to a mailbox:

New-MailboxImportRequest -FilePath \esp-ho-ex2010apstalan.reid.pst -Mailbox john.smith

However I'm not sure how to loop through a CSV file and use the values from it in this context.


Solution

  • Use the Import-Csv cmdlet to import the CSV, iterate over each record using the Foreach-Object cmdlet and access the current record within the foreach loop using $_:

    Import-Csv 'yourCsvPath.csv' -Header 'pst', 'email' | ForEach-Object {
        New-MailboxImportRequest -FilePath $_.pst -Mailbox $_.email
    }