Solved

Retrieving fileLastAccessed via fileSystemObject fails

Posted on 2007-12-04
2
317 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

21 Experts available now in Live!

Get 1:1 Help Now