Solved

Retrieving fileLastAccessed via fileSystemObject fails

Posted on 2007-12-04
2
319 Views
Last Modified: 2012-06-21
I have some code (attached) from a colleague that scans a remote computer looking for Outlook PST files and returns their location and size.

When I add in objFile.DateLastAccessed to the second-last line that begins with Wfile.writeline the code fails with the error:

C:\test2.vbs(12, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'objFile.DateLastAccessed'

So clearly that property doesn't exist.  How can I return the fileSystemObjects attributes DateLastAccessed and DateModified.

Key here is that the code runs remotely from a domain controller as we have some 3000 computers to scan and cannot run anything on the actual machines.

Background Info:
Have to audit a whole site for PST files on workstations for an upcoming mail server migration and consolidation.
Set WshShell = WScript.CreateObject("WScript.Shell")
 

strComputer = "AVT101397"

Set fso2 = CreateObject("Scripting.FileSystemObject")

set wfile2 = fso2.opentextfile("c:\b.csv",2,true)

Wfile2.writeline(strComputer)

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

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

Set fso = CreateObject("Scripting.FileSystemObject")

set wfile = fso.opentextfile("c:\b2.csv",2,true)

For Each objFile in colFiles

Wfile.writeline(strComputer & " " & objFile.Drive & " " & objFile.Path & " " & objFile.FileName & "." & objFile.FileSize)

next

Open in new window

0
Comment
Question by:wokwon
2 Comments
 
LVL 11

Accepted Solution

by:
bsharath earned 250 total points
ID: 20409425
See if this script helps..Save as vbs
edit the lines
arrComputers = Array("Machinename1,Machinename2")

On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim arrComputers, strComputer, objFSO, objFile, objWMIService, colItems
'Edit the Array statement on the next line to list the names of the computers you want to scan for pst files
arrComputers = Array("Machinename1,Machinename2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\PSTFileList.txt", True)
For Each strComputer In arrComputers
   objFile.WriteLine "Computer: " & strComputer
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT Name,FileSize,LastAccessed,LastModified FROM CIM_DataFile WHERE Extension='pst'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
   For Each objItem In colItems
      objFile.WriteLine "  Name: " & objItem.Name
      objFile.WriteLine "  FileSize: " & objItem.FileSize
      objFile.WriteLine "  LastAccessed: " & WMIDateStringToDate(objItem.LastAccessed)
      objFile.WriteLine "  LastModified: " & WMIDateStringToDate(objItem.LastModified)
   Next
Next
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objWMIService = Nothing
Set colItems = Nothing
WScript.Echo "All done"
WScript.Quit

Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
      WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
      Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
      & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function
0
 

Author Closing Comment

by:wokwon
ID: 31412791
Thank you that works well.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now