# Help with script to find all .pst files



## gleegeld (Sep 11, 2008)

Hello,

I'm trying to create a script that searches for all .pst files on a local pc and gathers the filename, path and size and outputs that data to a file called username.txt. I am having problems with my code. It creates the username.txt but does not write the .pst file information. Please help!


```
strComputer = "."
Const ForAppending = 2

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

Set colItems = objWMIService.ExecQuery("Select Username From Win32_ComputerSystem")

For Each objItem in colItems
    arrName = Split(objItem.UserName, "\")
    
Next

Set colItems = objWMIService.ExecQuery _
  ("Select * from CIM_DataFile Where Extension = 'pst' AND Drive = 'C:'")
 
If colItems.Count = 0 Then
    Wscript.Quit
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Script\" & arrName(1) & ".txt", ForAppending, True)

  For each ObjItem in colItems
    objFile.Write(arrName(1)& ",")
    objFile.Write(objFile.Drive & objFile.Path & ",")
    objFile.Write(objFile.FileName & "." & objFile.Extension & ",")
    objFile.Write(objFile.FileSize & vbCrLf)

Next
 objFile.Close
```


----------



## alcool9999 (Sep 16, 2008)

You could use a batch script. That can search for all of 1 type of file but to get the names and other information would be hard.


----------

