Solved

Retrieving fileLastAccessed via fileSystemObject fails

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

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