Solved

Retrieving fileLastAccessed via fileSystemObject fails

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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