[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to get all mdb file details for list of servers

Posted on 2013-11-20
7
Medium Priority
?
541 Views
Last Modified: 2014-04-04
Hi,

We need a script to get the list of all the files with extension mdb residing on the list of servers. We need the below listed attributes for all the files found in the excel format

1) Server on which they are found
2) location of the file
3) Name of the file
4) extension of the file
5) Date last modified of the file
6) Date last accessed
7) Size of the file

We have below script however it is not able to get the date last modified and date last accessed

On Error Resume Next

'open the file system object
Set FSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

Set Stream = FSO.OpenTextFile("C:\ServerList.txt")
computers = Split(Stream.ReadAll, vbNewLine)
Stream.Close

OutputFilePath="C:\Output.txt"

Set oReportFile = FSO.CreateTextFile(OutputFilePath, True)

For Each computer In computers
  Set objWMIService = GetObject("winmgmts:\\" & computer & "\root\cimv2")

  Set colFiles = objWMIService. _
      ExecQuery("Select * From CIM_DataFile Where Extension = 'MDB' ")


  If colFiles.Count = 0 Then
        Wscript.Echo "no exe files found"
            oReportFile.WriteLine(computer& "," & "No EXE File Found :)")

  Else
    For Each oFile in colFiles
var objfile = fso.getfile(oFile)
      oReportFile.WriteLine(computer & "!" & oFile.FileName & "!" & OFile.Path & "!" & OFile.drive & "!" & objFile.Extension  & "!" & Ofile.filesize)

        Next
  End If
Next
Set FSO=nothing
0
Comment
Question by:biplabmukh
  • 4
  • 2
7 Comments
 

Author Comment

by:biplabmukh
ID: 39663589
will appreciate a prompt response as need to prepare this report for management
0
 
LVL 26

Expert Comment

by:Lionel MM
ID: 39665640
If everything else is working as you want it you can add suggestions from this link -- will give you some ideas on how to get the the date modified info. http://www.tek-tips.com/viewthread.cfm?qid=1602861 and these two links for last accessed
http://steves-rant.blogspot.com/2006/11/last-accessed-vbs-script.html
http://ns7.webmasters.com/caspdoc/html/vbscript_file_object_datelastaccessed_property.htm
0
 

Author Comment

by:biplabmukh
ID: 39667084
however not able to successfully insert the function to get the last modified file

is it possible to integrate the scripts shared by you in the above script to get the dat last modified ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:Lionel MM
ID: 39667929
You can take pieces and parts and combine them. What happens when you try to insert the required functions. Please re-post your new code and the results--thanks.
0
 

Author Comment

by:biplabmukh
ID: 39668715
when i am running the below modified script it is running but writing nothing in the output file. However, when i replace the

below part

    "  oReportFile.WriteLine(computer & "!" & oFile.FileName & "!" & OFile.Path & "!" & OFile.drive & "!" & objFile.DateLastModified  & "!" & Ofile.filesize) "

with below :-

    Wscript.Echo "Creation date: " & oFile.CreationDate
    Wscript.Echo "Computer system name: " & oFile.CSName
    Wscript.Echo "Drive: " & oFile.Drive
    Wscript.Echo "Extension: " & oFile.Extension
    Wscript.Echo "File name: " & oFile.FileName
    Wscript.Echo "File size: " & oFile.FileSize
    Wscript.Echo "File type: " & oFile.FileType
    Wscript.Echo "File system name: " & oFile.FSName
    Wscript.Echo "Last accessed: " & oFile.LastAccessed
    Wscript.Echo "Last modified: " & objFile.LastModified

it is showing the last access and last modified information correctly but it is not writing it out, any idea why it is behaving like this ?

in output file it just write nothing
0
 
LVL 2

Accepted Solution

by:
daniel0 earned 2000 total points
ID: 39677538
0
 

Author Closing Comment

by:biplabmukh
ID: 39978735
thanks for sharing the input.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

810 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