Partager via


Scripting: Listing PST files in an outlook profile

One of my clients was in a nasty situation, he had a ton of users with PST files on the fileserver and they wanted that changed. Understandable as it is an unsupported situation Smile. Now the real problem is that every option we went over required a ton of manual labor which, in an environment of 20 000 mailboxes with hot desks, was not an option. So with the clients requirements in hand I created a vbs script which would work for all of their workstations (running different OS and outlook versions –_- ) and could be used to collect data on where the PST files are located….

 

  

  
  
 Dim objNetworkSet, objFSO, objFolder, objShell, objTextFile, objFile, objWMISysEnv,ObjItem, objTextFileUNC
 Dim strHomePath, strDirectory, strFile, strText, strComputerName,strDirectoryUNC,strFileUNC
 dim colItems
  
 Set objNetwork = CreateObject("WScript.Network")
 Set objOutlook = CreateObject("Outlook.Application")
 Set objNS = objOutlook.GetNamespace("MAPI")
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set wshShell = WScript.CreateObject("WScript.Shell")
  
 ' Setting file names
 strDirectory = "c:\users\marcdek\temp"
 strFile = "\" & ObjNetwork.Username &"-PSTOUTPUT.txt"
  
 strDirectoryUNC=
 strFileUNC=
  
 ' Check to see if the file already exists exists
 If objFSO.FolderExists(strDirectory) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
 Else
    Set objFolder = objFSO.CreateFolder(strDirectory)
 End If
  
 If objFSO.FileExists(strDirectory & strFile) Then
    Set objFolder2 = objFSO.GetFolder(strDirectory)
 Else
    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
 End If 
  
 ' OpenTextFile Method needs a Const value
 ' ForAppending = 8 ForReading = 1, ForWriting = 2
 Const ForAppending = 8
  
 ' Opening text file
 Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
 Set objTextFileUNC= objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
 ' Here we go!
 For Each objFolder2 In objNS.Folders
      objTextFile.WriteLine(GetPSTPath(objFolder2.StoreID))
      objTextFileUNC.WriteLine(GetPSTPath(objFolder2.StoreID))
  Next
   
  Function GetPSTPath(input)
      For i = 1 To Len(input) Step 2
          strSubString = Mid(input,i,2)    
         If Not strSubString = "00" Then strPath = strPath & ChrW("&H" & strSubString)
      Next
     
     Select Case True
          Case InStr(strPath,":\") > 0  
             GetPSTPath = Mid(strPath,InStr(strPath,":\")-1)
          Case InStr(strPath,"\\") > 0  
             GetPSTPath = Mid(strPath,InStr(strPath,"\\"))
      End Select
  End Function
  
  
 If err.number = vbEmpty then
   Else WScript.echo "VBScript Error: " & err.number
 End If

Comments

  • Anonymous
    January 01, 2003
    Great script... but..I have a need to:-connect any new users to a particular Windows 7 Pro (outlook 2007) machine to ALL PST files within C:Outlook*.pstcould I be cheeky and ask for assistance on this one please? the computer - due to restrictions - is NOT part of a domain. and I am an administrator.Many Thanks

  • Anonymous
    May 11, 2012
    please correct me if i am wrong, but isn't this script the same as the one posted here: blogs.technet.com/.../scripting-adding-pst-files-to-an-outlook-profile-automatically.aspx to add the PSTs to the Outlook profile? Also, there is a PST discovery tool that was recently rolled out by MS to perform these steps through a GUI - PST Capture www.microsoft.com/.../details.aspx

  • Anonymous
    May 12, 2012
    Fixed it :)

  • Anonymous
    May 12, 2012
    On the PST Discovery tool: This script only lists the PSTs. The client in question wanted to keep pst files in place but know where they were and move them to local discs.

  • Anonymous
    December 18, 2013
    XOUser8334, have a look at this one: http://blogs.technet.com/b/messaging_and_beyond/archive/2012/05/10/scripting-adding-pst-files-to-an-outlook-profile-automatically.aspxWith some adaptation it should be possible to get a list of all files with a PST extension and connect them in to outlook

  • Anonymous
    January 20, 2014
    can u please tell me which part that need to modify to make this script work at my pc?

  • Anonymous
    February 20, 2014
    The comment has been removed

  • Anonymous
    April 15, 2014
    The comment has been removed

  • Anonymous
    February 11, 2015
    Thanks for script. But i have a problem with output file characters. Russian letters in that file shows corrupted like "C:UsersevgDocuments$09;K Outlookarchive.pst" Plz! help resolve this problem! or maybe some advise help