Reputation: 1
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)
Upvotes: 0
Views: 152
Reputation: 3440
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
Upvotes: 1
Reputation: 38775
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.
Upvotes: 0