Pages

Friday, September 15, 2006

Exchange: Search Network For PST Files

Summary:

In this article, I will provide a script to search your network for .PST files. Microsoft provides a script to search your local computer for a .PST file which you can find here.

http://www.microsoft.com/technet/scriptcenter/resources
/qanda/apr05/hey0408.mspx

I have modified it to also include the computer name since it will be intended to search multiple computers and to write the output to a csv file.

Copy the contents below and save to notepad. Rename this file to searchpst.vbs and save to C: drive.


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _

("Select * from CIM_DataFile Where Extension = 'pst'")

Set fso = CreateObject("Scripting.FileSystemObject")

set wfile = fso.opentextfile("c:\test.csv",2,true)

For Each objFile in colFiles

Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.Extension & " " & objFile.FileSize)

Next




Open your command prompt. Start, Run, CMD Ok. Ensure that you are at your your C:\>

Type the following

C:\>cscript searchpst.vbs

Once complete, go to your C: drive and locate text.csv. This csv file should include your computername, drive letter and path of your pst file, name of pst file and size.



Now if you wish to run this on multiple computers on the network you have couple options.

C:\>cscript searchpst.vbs computer1 computer2 computer3


Another option is to have this script read in the computer names from your computers OU in AD.

Copy the contents below to notepad. Save the file as searchpst1.vbs. Open your command prompt and type:

C:\>cscript searchpst1.vbs

Set colComputers = GetObject("LDAP://CN=Computers, DC=msexchange911, DC=net")
For Each objComputer in colComputers
strComputer = objComputer.CN
on error Resume next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Extension = 'pst'")
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\test.csv",2,true)
For Each objFile in colFiles
Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.Extension & " " & objFile.FileSize)
next
next


References:

Running WMI Scripts on Multiple Computers
http://www.microsoft.com/technet/scriptcenter/resources
/tales/sg1102.mspx

How Do I Get a List of All PST Files on a Computer
http://www.microsoft.com/technet/scriptcenter/resources
/qanda/apr05/hey0408.mspx


James Chong
MCSE | M+, S+, MCTS, Security+
msexchangetips.blogspot.com

How useful was this article? Want to see a tip not listed? Please leave a comment.

39 comments:

  1. Anonymous4:44 AM

    Hi When I ran the first script I got the following error, can you help me out..?

    C:\>cscript Searchpst.vbs
    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    C:\Searchpst.vbs(6, 1) Microsoft VBScript compilation error: Expected statement

    Thanks
    Abhishek

    ReplyDelete
  2. Anonymous5:39 AM

    thanks, running script now on WS's. do you have one for finding psts in user shares?

    ReplyDelete
  3. Anonymous5:52 AM

    I received the same error as Abishek.

    Thanks

    ReplyDelete
  4. For work with exchange and other mails files-microsoft exchange pst password recovery,application is free as how as i remember,it works with the following mail accounts and services, such as IMAP mail servers, POP3 mail servers, Microsoft Exchange Server, web-based email and Microsoft Mail,except mail accounts, the program can unlock password protected files with *.pst extension,will sort all characters and find a password for you,recover passwords Outlook Exchange, when you cannot recover the password of an Exchange .pst or forgotten password Outlook Exchange Server.

    ReplyDelete
  5. With mails I worked for a long time,but programs for recover them I saw many.But one of them for me is the best-outlook 2003 pst recovery.Because it is free,program is reliable,besides that it can too view recovered messages in *.eml format even without Microsoft Outlook email client.

    ReplyDelete
  6. Its highly informative. I would be visiting your blog hereafter regularly to gather valuable information.
    Real Estate Script

    ReplyDelete
  7. Anonymous8:56 AM

    Script queries ALL available drive letters, which will slow the time to completion.
    Is there a refinement of the GetObject() query that asks the cimv2 namespace for just local drives ?

    otherwise, great scrip - thanks
    Uncle_Nick

    ReplyDelete
  8. Great post and very well written, that will really help you to learn Web Design, web development and SEO Strategies to help businesses web design company . You can find out many useful information about web design, seo and his work by visiting his blog and I Just wanna say thanks you for the information you have shared. Web Design Company India

    ReplyDelete
  9. Anonymous5:45 PM

    For many people, the first type of Men’ Footwear that we believe that during the consideration of Hogan scarpe for men in May of tennis shoes or even a generic cross-training shoes. For others, they believe in May of Hogan scarpe donna , it depends on your background. In fact, this category of hogan donna covers a wide range of sports shoes and leisure activities ranging from golf and basketball and soccer shoes race. I tend to buy Hogan scarpe uomo against training only because I am involved in a wide range of sports and weightlifting, the race to play basketball.

    ReplyDelete
  10. thanks! works great!

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Anonymous1:16 PM

    PLEASE help
    hi I have the same error as form the comment below:



    C:\>cscript Searchpst.vbs
    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    C:\Searchpst.vbs(6, 1) Microsoft VBScript compilation error: Expected statement

    ReplyDelete
  13. This is really amazing. You helped me to open up my eyes. Thanks for publishing and I'm looking forward to your new posts.
    John F. from VpsWebServer.
    Visit us and learn all about vps hosting.

    ReplyDelete
  14. Wonderful blog post,I will save it to favorites and let all my friends know about it. It's been a pleasure to read something like this.

    Learn all about Microsoft Exchange.

    ReplyDelete
  15. Anonymous11:21 AM

    This was SO helpful! Thank you so much!!!!

    ReplyDelete
  16. Do pst files contain all the profile information needed to set up Outlook 03 on a new computer?

    ReplyDelete
  17. Two PST files in my laptop, one ask for password other cant be access denied how do i solve this problem?

    ReplyDelete
  18. How to import .pst files from another email account in such a way dat those emails do not mix with d existing?

    ReplyDelete
  19. Two PST files in my laptop, one ask for password other cant be access denied how do i solve this problem?

    ReplyDelete
  20. Quite effective material, thank you for the article.

    ReplyDelete
  21. How to import .pst files from another email account in such a way dat those emails do not mix with d existing?

    ReplyDelete
  22. How to import .pst files from another email account in such a way dat those emails do not mix with d existing?

    ReplyDelete
  23. Why do i get an application error whenever i open a new window?

    ReplyDelete
  24. Anonymous2:44 AM

    if you don't respond to errors which people are encountering then this is pretty useless!

    C:\>cscript Searchpst.vbs
    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    C:\Searchpst.vbs(6, 1) Microsoft VBScript compilation error: Expected statement

    ReplyDelete
  25. Anonymous5:39 AM

    C:\Searchpst.vbs(6, 1) Microsoft VBScript compilation error: Expected statement

    Probably a formatting error?

    ReplyDelete
  26. Anonymous5:22 AM

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colFiles = objWMIService.ExecQuery("select * from CIM_DataFile Where Extension = 'pst'")

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set wfile = fso.opentextfile("c:\pst\test.csv",2,true)

    For Each objFile in colFiles

    Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.Extension & " " & objFile.FileSize)

    Next

    Working script

    ReplyDelete
  27. Anonymous2:34 PM

    Pstviewer.com has software for viewing and searching .pst files without Outlook.

    ReplyDelete