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

Recommended Answers

All 2 Replies

Do you use Visual Basic? or just VBScript??

objFile is your TextStream object. You need to pull the properties off of the Enumerated ObjItem object. objFile.Write([U]objItem[/U].Drive...)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.