rschraeger
asked on
VBscript Help
I have a script that is searching for extentions on a drive. If that extention is found it writes the information to a file. It works great except when I try to add the obj.datelastmodified to the output file. when I add that object the file returns empty. If I take that out then I get the results.
How can I get my output to show the last modified date?
How can I get my output to show the last modified date?
' SCAN FOR FILES WITH EXTENSION
strInput = "mdb"
strInput1 = "wp"
strInput2 = "wp4"
strInput3 = "wp5"
strInput4 = "wp6"
strInput5 = "wp7"
strInput6 = "wb2"
strInput7 = "wpd"
Set colComputers = GetObject("LDAP://ou=SCAN,ou=Servers,DC=domain,DC=local")
For Each objComputer In colComputers
strComputer = objComputer.CN
on error Resume next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where (Extension = '" & strInput &"' OR Extension = '" & strInput1 &"' OR Extension = '" & strInput2 &"' OR Extension = '" & strInput3 &"' OR Extension = '" & strInput4 &"' OR Extension = '" & strInput5 &"' OR Extension = '" & strInput6 &"' OR Extension = '" & strInput7 &"') AND (Drive = 'F:') ")
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\SCANS\New.csv",2,true)
For Each objFile in colFiles
Wfile.writeline(strComputer & "," & objFile.Drive & "\" & objFile.Path & "\" & objFile.FileName & "." & objFile.Extension & "," & objFile.FileSize & "," & objFile.DateLastModified)
next
next
Is it a typo, or did you really use
obj.datelastmodified
instead of
objFile.datelastmodified
?
obj.datelastmodified
instead of
objFile.datelastmodified
?
ASKER
It is objfile.datelastmodified
Try writing the DateLastModified value to a variable and examining it in a MsgBox. You might need to check it for validity before writing it to a text file.
Remove the following line, and run again, seeing if you get any errors.
on error Resume next
~bp
You need to change
objFile.DateLastModified
to
objFile.LastModified
The WMI execution isn't returning a FileSystem file object, but rather a CIM_Datafile class member.
That being said, what you will see in the CSV file will likely be in a format like this for the date:
20120120112210.687139-300
Which may or not be what you want.
~bp
objFile.DateLastModified
to
objFile.LastModified
The WMI execution isn't returning a FileSystem file object, but rather a CIM_Datafile class member.
That being said, what you will see in the CSV file will likely be in a format like this for the date:
20120120112210.687139-300
Which may or not be what you want.
~bp
There are a number of conversion routines out there for dealing with WMI datetime objects, for example:
http://www.aspfree.com/c/a/Windows-Scripting/Working-with-Dates-in-WMI/
http://technet.microsoft.com/en-us/library/ee156576.aspx
http://www.thescriptlibrary.com/Default.asp?Action=Display&Level=Category3&ScriptLanguage=VBScript&Category1=Scripting%20Techniques&Category2=Dates%20and%20Times&Title=Convert%20WMI%20Date-Time%20Values
~bp
http://www.aspfree.com/c/a/Windows-Scripting/Working-with-Dates-in-WMI/
http://technet.microsoft.com/en-us/library/ee156576.aspx
http://www.thescriptlibrary.com/Default.asp?Action=Display&Level=Category3&ScriptLanguage=VBScript&Category1=Scripting%20Techniques&Category2=Dates%20and%20Times&Title=Convert%20WMI%20Date-Time%20Values
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
myString = strComputer & "," & objFile.Drive & "\" & objFile.Path & "\" & objFile.FileName & "." & objFile.Extension & "," & objFile.FileSize & "," & objFile.DateLastModified
then write it out...
Wfile.writeline(myString)