none
How to change default PST for Outlook 2010 using a script (VBS, batch, powershell.) RRS feed

  • Question

  • In Outlook 2010, I have to :-

    * create a new PST file "New.PST"

    * mark the file "New.PST" as default.

    * delete the original default PST file.

    Is there any way to  automate the above steps using a script (VBS, Batch, Powershell.).

    We have to configure outlook when the user logs on.Any help is much appreciated. 


    Tuesday, December 16, 2014 1:01 PM

Answers

  • Outlook Object Model would not let you change the default store, you can only do that in Extended MAPI (C++ or Delphi).

    If using Redemption (which wraps Extended MAPI is an option), you can try to set its RDOStore.Default property. Something like the following (off the top of my head):

    Set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set OldDefaultStore = Session.Stores.DefaultStore
    set NewStore = Session.Stores.AddPstStore("c:\SomePstFile.pst")
    NewStore.Default = true
    OldDefaultStore.Remove 


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by SumitRoy Wednesday, December 17, 2014 6:46 AM
    Tuesday, December 16, 2014 2:33 PM

All replies

  • Hello,

    The Outlook object model provides the following methods for that:

    1. AddStore / AddStoreEx - adds a Personal Folders (.pst) file to the current profile. If the .pst file does not exist, Microsoft Outlook creates it.

    2. RemoveStore - Removes a Personal Folders file (.pst) from the current MAPI profile or session. This method removes a store only from the Microsoft Outlook user interface. You cannot remove a store from the main mailbox on the server or from a user's hard disk using the Outlook object model. You are free to use System.IO classes for removing file from the disk.

    But the OOM doesn't provide any methods or properties for marking them as default.

    Tuesday, December 16, 2014 1:21 PM
  • Outlook Object Model would not let you change the default store, you can only do that in Extended MAPI (C++ or Delphi).

    If using Redemption (which wraps Extended MAPI is an option), you can try to set its RDOStore.Default property. Something like the following (off the top of my head):

    Set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set OldDefaultStore = Session.Stores.DefaultStore
    set NewStore = Session.Stores.AddPstStore("c:\SomePstFile.pst")
    NewStore.Default = true
    OldDefaultStore.Remove 


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by SumitRoy Wednesday, December 17, 2014 6:46 AM
    Tuesday, December 16, 2014 2:33 PM
  • Thanks for your inputs, have already tested AddStore and RemoveStore.

    real concern was the default PST, which I don't think can be done thru scripts.

    Wednesday, December 17, 2014 6:43 AM
  • Unfortunatley I have to work with VBS or Powershell (organization policy). But thanks for your inputs, will surely check it out.

    Wednesday, December 17, 2014 6:45 AM