Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File/Folder Mapper with logging not working remotely

Status
Not open for further replies.

Sasstraliss

Programmer
Apr 7, 2009
21
AU
Alright. I am looking for a script that logs all files, folders, and subfolders (and sub files) of any drive on a remote computer.

I found a script that does it, BUT it does not do sub directories or folders.

Code:
strComputer = (InputBox(" Computer name:", "Z Basic"))
If strComputer <> "" And strComputer <> "q" And strComputer <> "e" Then

Const ForAppending = 2
LogFile = "Z:\Documents\Op. S 2.1\zz--Collected Data\Map Logs\Z-Basic.log"
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLogFile:Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='Z:\'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile In colFileList
    objLogFile.Write objFile.Name
    objLogFile.Writeline
Next

objLogFile.Close

End if


I also found another script that does sub folders, and does everything I want, however it does not work remotely, and this is because strComputer is not justified later on in the script.

Code:
strComputer = (InputBox(" Computer name:", "Z Adv"))
If strComputer <> "" And strComputer <> "q" And strComputer <> "e" Then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 2
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")

LogFile = "Z:\Zzz.log"
Dim objLogFile:Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)

objStartFolder = "Z:\"

Set objFolder = objFSO.GetFolder(objStartFolder)
objLogFile.Write objFolder.Path
objLogFile.Writeline
Set colFiles = objFolder.Files
For Each objFile in colFiles
    objLogFile.Write objFile.Name
    objLogFile.Writeline
Next


ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        objLogFile.Write Subfolder.Path
        objLogFile.Writeline
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
            objLogFile.Write objFile.Name
            objLogFile.Writeline
        Next
        ShowSubFolders Subfolder
    Next
End Sub
objLogFile.Close

End if


If someone can help me get a working script that logs files, folders, and SUB FOLDERS/FILES remotely, then this would be very greatly appreciated.

Thankyou in advance.
 
Look up the use of WSHRemote to execute the FileSystemObject script remotely.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top