Open-MapiPST

Description

This cmdlet is used to open or create PST files.  It can either open a PST in an existing MAPI Session, or can create a new profile specific to the PST file.

Syntax
Note: Parameters in orange are optional.
Open-MapiPST
-SessionMapiObject<Mapi.NET.Session>
-PstFilePathString
-PasswordString
Open-MapiPST
-SessionMapiObject<Mapi.NET.Session>
-PstFileInfoSystem.IO.FileInfo
-PasswordString
Open-MapiPST
-SessionMapiObject<Mapi.NET.Session>
-PstFilePathString
-CreateNewSwitchParameter
-CreateAnsiPSTSwitchParameter
-PasswordString
Open-MapiPST
-SessionMapiObject<Mapi.NET.Session>
-PstFileInfoSystem.IO.FileInfo
-CreateNewSwitchParameter
-CreateAnsiPSTSwitchParameter
-PasswordString
Open-MapiPST
-PstFilePathString
-PasswordString
Open-MapiPST
-PstFilePathString
-CreateNewSwitchParameter
-CreateAnsiPSTSwitchParameter
-PasswordString
Open-MapiPST
-PstFileInfoSystem.IO.FileInfo
-PasswordString
Open-MapiPST
-PstFileInfoSystem.IO.FileInfo
-CreateNewSwitchParameter
-CreateAnsiPSTSwitchParameter
-PasswordString
Parameters
SessionA Mapi.NET.Session object in which to open the PST file.
PstFilePathA text string that is the full path to the PST file to open or create.
PstFileInfoA System.IO.FileInfo object that represents the PST file to open.
PasswordAn optional text string that is used to open a password protected PST file, or to set a password on when creating a new PST file.
CreateNewA SwitchParameter which, if present, causes a new PST file to be created with the specified PST file name.
CreateAnsiPSTAn optional SwitchParameter only used with CreateNew which, if present, causes the new PST file being created to be in the older, and smaller, ANSI format.
Remarks

This cmdlet can either create or open a PST file and returns a Mapi.NET.Store object for the PST with which other cmdlets can be used to access its contents.

Note that PST files, when opened by a MAPI application are opened for exclusive read/write access.  This means that only one application can open a PST file at a time.  If a PST file is current open in Outlook, this cmdlet will fail when trying to open that PST file as the file will be locked by the Outlook application.  In such a case, use New-MapiSession to open a shared session with Outlook and open the PST store from that session.

While not prevented, PST files should not be opened over a network connection (from a UNC path, for example).  MAPI's communication with the PST file is not very tolerant to network drops and can corrupt a PST file.  Furthermore, MAPI is very "chatty" and uses many file operations with PSTs and is not very efficient for network use.  When possible, a remote PST file should be copied locally and then opened.

When this cmdlet is used to open a PST file without using an existing session, a new temporary MAPI profile is created.  The profile name will start with "PowerMapi-PstProfile:" followed by some random characters to guarantee uniqueness.  The profile will be deleted when the returned Store object is disposed and the underlying session is closed.  However, if the script or command exits prematurely, the profile may still be listed as a profile in the list of MAPI profiles.  Use the Remove-MapiProfile cmdlet to remove such profiles if necessary.

PST files can be in one of two formats: ANSI or Unicode.  The older ANSI format was the original format and supported file sizes up to 2GB.  The newer Unicode format supports file sizes up to approximately 30gb (with some variance depending upon data types in the store).  This cmdlet, when creating new PST files, defaults to the Unicode version unless the CreateAnsiPST switch is used.  Note that the Unicode version was first provided in Outlook 2003.  Attempting to create a Unicode PST with versions prior to Outlook 2003 will fail and the CreateAnsiPST switch is required.

There are also some other restrictions with PST files with regards to item and attachment size as well as total folder counts.  Refer to Microsoft's documentation on such limitations.