0

I apologize in advance for my "newness" to vbs. I am trying to run this script to search for all pst files on my file server. At this point, I am getting this error:

searchpst.vbs(6, 26) Microsfot VBScript compilation error: Expected end of statement.

the script I am trying to run is of course named searchpst.vbs, and I know the (6, 26) is the line and charecter number of the error, but I cant seem to figure out what to do to fix it? Below is my script, and help is greatly appreciated!

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
strsql = "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)

2 Answers 2

1

I've reformatted the code for easier readability. The single apostrophe ' changes everything behind it into a comment, so it's not part of the code. So '"pst"'" isn't visible.

Actually, there are more problems than just that. That whole line is formatted incorrectly, and I think you've got a couple other lines out of order. It should look like this, I think:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strsql = "Select * from CIM_DataFile Where Extension = 'pst'"
Set colFiles = objWMIService.ExecQuery(strsql)
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
Sign up to request clarification or add additional context in comments.

1 Comment

Joe, thanks a million! It worked perfectly. I really appreciate it!!
0

You need param list (), if you call a function to receive its return value; and _ continues a line - so change:

Set colFiles = objWMIService.ExecQuery _
strsql = "Select" * from CIM_DataFile Where Extension = '"pst"'"

to

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

or:

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

After reading @Joe's (+1) answer, I tried to clean up the quoting in your SQL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.