Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share|improve this question

2 Answers 2

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
share|improve this answer
    
Joe, thanks a million! It worked perfectly. I really appreciate it!! –  user2414682 May 23 '13 at 18:19

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.