1

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.

user6888062
  • 353
  • 1
  • 3
  • 16

1 Answers1

1

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
}
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • Thanks. I'll need to add a row `pst,email` to the top, right? – user6888062 Feb 22 '17 at 12:58
  • No, I assumed your csv doesn't contains a header thats why I provided it. If your CSV contains a header, you can omit the `-Header` parameter and use the header names instead when accessing `$_.` – Martin Brandl Feb 22 '17 at 13:03
  • Ah, sorry I should have read up on `-Header`, so that's exactly what I want, and I don't need to add the row. Great. Thanks – user6888062 Feb 22 '17 at 13:40