?
Solved

Retrieving fileLastAccessed via fileSystemObject fails

Posted on 2007-12-04
2
Medium Priority
?
333 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
[X]
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
2 Comments
 
LVL 11

Accepted Solution

by:
bsharath earned 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

752 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