Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBscript Help

Posted on 2012-04-13
9
582 Views
Last Modified: 2012-04-21
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?

'  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

Open in new window

0
Comment
Question by:rschraeger
9 Comments
 
LVL 9

Expert Comment

by:jsdray
ID: 37843430
Just out of curiosity...try setting a variable for your output...

myString = strComputer & "," & objFile.Drive & "\" & objFile.Path & "\" & objFile.FileName & "." & objFile.Extension & "," & objFile.FileSize & "," & objFile.DateLastModified

then write it out...

Wfile.writeline(myString)
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 37843440
Is it a typo, or did you really use
  obj.datelastmodified
instead of
  objFile.datelastmodified
?
0
 

Author Comment

by:rschraeger
ID: 37843758
It is objfile.datelastmodified
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 37843930
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.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37844190
Remove the following line, and run again, seeing if you get any errors.
on error Resume next

Open in new window

~bp
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37844250
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
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37844300
0
 
LVL 9

Accepted Solution

by:
Scottyworld earned 500 total points
ID: 37858880
As Bill said, you need to use objFile.LastModified and pipe the result through a function that converts the date to a readable format
The below script should do all of that for you
' 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
		strLastMod = DatetimeToDate(objFile.LastModified)
		Wfile.writeline(strComputer & "," & objFile.Drive & "\" & objFile.Path & "\" & objFile.FileName & "." & objFile.Extension & "," & objFile.FileSize & "," & strLastMod)
	next
next

Function DatetimeToDate(strDate)
   DatetimeToDate = CDate(Mid(strDate, 5, 2) & "/" & Mid(strDate, 7, 2) & "/" & Left(strDate, 4) & " " & Mid (strDate, 9, 2) & ":" & Mid(strDate, 11, 2) & ":" & Mid(strDate, 13, 2))
End Function

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question