New-MailboxImportRequest 1-line script


In performing a domain migration the user accounts were created before the email accounts were scheduled to be migrated. We added email to the newly created accounts but got the pst data several days later. Each pst file is named after the user alias. Now I needed a script to import the pst’s.

I have a csv file with the following data:

ADsPath sAMAccountName mail pstpath
“LDAP://domain.local/CN=Charlie Brown,OU=Users,DC=sub,DC=DOMAIN,DC=local” cbrown \\sharedfolder\encryptedfolder\cbrown.pst


[PS] C:\>foreach ($i in (import-csv C:\EncryptedFolder\PSTList.csv)) {New-MailboxImportRequest -Mailbox $i.sAMAccountName -FilePath $i.pstpath -DomainController server.domain.local}

The key in this script is that you have to loop through your file hence the “foreach” cmdlet.

At first I started with this script:

[PS] C:\>import-csv c:\encryptedfolder\PSTList.csv | New-MailboxImportRequest -Filepath $_.pstpath -Mailbox $sAMAccountName -DomainController server.domain.local

However this failed with the error of: “Cannot validate argument on parameter ‘FilePath’. The argument is null.” Which is of course a correct message because I omitted the loop so there is no value for the parameter.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s