0

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
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by techtix
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.