I am new in VBS and trying to write a script to (first) find PST files in the user's profile. In Outlook 2007 the default location for these files is %userprofile%\AppData\Local\Microsoft\Outlook, but in Outlook 2010 is %userprofile%\Documents\Outlook Files.
For the moment I've tested with the below code, and for testing purposes I used a folder C:\Data and the path for Outlook 2007. Both containing PST files.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Extension = 'pst' AND (Path = '\\Data\\' OR Path = '\\" & strUserName &"\\AppData\\Local\\Microsoft\\Outlook')")
The problem is that it successfully reads from the Data folder but from the user profile does not. The interesting thing is that If I state the Drive = 'C:' instead of the two paths in query, it returns all pst files from both Data and %userprofile%\AppData\Local\Microsoft\Outlook. But looking through all C drive is not the best solution as it consumes precious resources for nothing.
Any ideas how to make it access those two folders?
Thanks and advance! Iulian