Messaging and beyond!

Tales of an MS Exchange PFE

Scripting: Adding PST files to an outlook profile automatically

Scripting: Adding PST files to an outlook profile automatically

  • Comments 6
  • Likes

This script will allow you to add all PSTs in a txt file (full path).

On error resume next
    Const ForReading = 1 
    Dim arrFileLines() 
    Dim objNetwork,ObjFSO,objFile,objNet,objOutlook
    
    i=0
    
    Set objnet = CreateObject("wscript.network")
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile("c:\users\marcdek\temp\"& objNet.Username & "-PSTOUTPUT.txt", ForReading) 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objOutlook = CreateObject("Outlook.Application") 
 
    Do Until objFile.AtEndOfStream 
        Redim Preserve arrFileLines(i) 
        arrFileLines(i) = objFile.ReadLine 
                i = i + 1 
    Loop 
    
    objFile.Close
    
    For Each strPath in arrFileLines 
         objOutlook.Session.Addstore strPath
    Next  

And if you want to add a selection to only add local PST files you use the following:

On error resume next
    Const ForReading = 1 
    Dim arrFileLines() 
    Dim objNetwork,ObjFSO,objFile,objNet,objOutlook
    
    i=0
    
    Set objnet = CreateObject("wscript.network")
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile("c:\users\marcdek\temp\"& objNet.Username & "-PSTOUTPUT.txt", ForReading) 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objOutlook = CreateObject("Outlook.Application") 
 
    Do Until objFile.AtEndOfStream 
        Redim Preserve arrFileLines(i) 
        arrFileLines(i) = objFile.ReadLine 
                i = i + 1 
    Loop 
    
    objFile.Close
    
    For Each strPath in arrFileLines 
         Select Case True
            Case InStr(strPath,":\") > 0  
                objOutlook.Session.Addstore strPath
            Case InStr(strPath,"\\") > 0  
            End Select
    Next  
Comments
  • What code would be needed in order for the script to scan a particular file on the local machine to auto populate the data in the -PSTOUTPUT.txt so I could run the code on a rebuilt machine and auto add all the .pst files on the machine to the usser's outlook profile? Some of my clients have hundreds of pst files and adding them individually is a big time waster.

  • Hi DraakusM,

    You could use the following script to populate that list:

    blogs.technet.com/.../scripting-listing-pst-files-in-an-outlook-profile.aspx

  • Exactly what I was looking for (with over 100 PSTs... don't ask. :) )

    One caveat for people... if one or more of them is corrupt, it can take a LONG time for it to come back from the script.  You might want to break up your list into 10 file chunks (or less) and just keep repopulating the file list.

    Thank you!

  • Where i put the txt file?

  • If my supposition is good... for exemple the username of the user is
    Bblaze the path Will be:
    C:\users\marcdek\temp\bblaze-PSTOUTPUT.txt

  • C:\users\bblaze\temp\bblaze-PSTOUTPUT.txt

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment