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

x
?
Solved

Get all the file names of a remote machine to a file.

Posted on 2007-07-21
14
Medium Priority
?
317 Views
Last Modified: 2010-03-05
Hi,

I have a list of machine names .Can i have a script to scan the machine and get the file names to a txt file.

Ex:
C:\filename.txt
C:\filename.bmp
etc

Regards
Sharath
0
Comment
Question by:bsharath
14 Comments
 
LVL 26

Expert Comment

by:Farhan Kazi
ID: 19540170
Can you please specify drive, path or file types you want to include in scan? or you want list of all files (it will be very difficult for you to read that output file).
0
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 19540905
0
 
LVL 11

Author Comment

by:bsharath
ID: 19541722
I Need to get for a specific drive
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:bsharath
ID: 19544934
Any help
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19553909
Hi Sharath,

I just posted a script here:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22712374.html

that could be changed to suit this question.  Is there a specific set of files that you want to get a list of, or you want to know ALL of the files for a speicific drive on a remote machine?

Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 19553985
The posted one is to find and delete.But this is to search and get all the names to a file

Ex:
C:\filename.txt
C:\filename.bmp
etc
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19554062
Every single file on a specific drive?
That's going to be a large text file.....and may just better using
dir /s > Files.txt
remotely........

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19554070
Actually, come to think of it, I think that would be much faster.....I might change the other one as well....tomorrow though, it's late now.....

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 19554265
Ok thanks
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 19561945
Hi Sharath,

Here is a script that uses the DIR command to return the list of files per drive, for computers in a text file.
When it runs, you specify which drive(s) to list, and when it's finished, it opens the text file that the files were dumped to, separated by a line that says
COMPUTER: <computername>

'=====================
Option Explicit

Dim strComputer, strFile, strFileName, strExtension, boolFileFound, strFileList, arrFileList, intCount, objWMIService, colFileList, objFile, boolPinged
Dim objFSO, objComputerFile, objFileNameFile, strComputerFile, strFileNameFile, strResponse, strCommand, objShell, strDrives, arrDrives, strOutputFile
Const intForReading = 1

strComputerFile = "Computers.txt"
strFileNameFile = "FilesToDelete.txt"
strOutputFile = "\\D09790RING\C$\Temp\Files.txt"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strOutputFile = objFSO.GetFile(strOutputFile).ShortPath
Set objComputerFile = objFSO.OpenTextFile(strComputerFile, intForReading, False)
'strComputer = InputBox("Please enter the computer IP or hostname that you want to look for a file on:", "Computer to search", "172.16.2.64")
'strFileName = InputBox("Please enter the file name (no extension) to search for:", "File name to search for", "firefox")
'strExtension = InputBox("Please enter the extension of the file name to search for:", "File name extension to search for", "exe")
strDrives = InputBox("Please enter the drives to output, comma separated (eg: c,d):", "Drives to list file of", "C")
arrDrives = Split(strDrives, ",")
For intCount = LBound(arrDrives) To UBound(arrDrives)
      arrDrives(intCount) = Left(arrDrives(intCount), 1)
Next

strCommand = "cmd /c echo. > " & strOutputFile
objShell.Run strCommand, 0, True

While Not objComputerFile.AtEndOfStream
      strComputer = objComputerFile.ReadLine
      boolPinged = Ping(strComputer)
            
      If boolPinged = "True" Then

            strCommand = "cmd /c echo. >> " & strOutputFile & " && echo Computer: " & strComputer & " >> " & strOutputFile & " && echo =================== >> " & strOutputFile
            objShell.Run strCommand, 0, True
      
            For intCount = LBound(arrDrives) To UBound(arrDrives)
                  arrDrives(intCount) = Left(arrDrives(intCount), 1)
                  strCommand = "cmd /c \\mccdc01\netlogon\psexec_182.exe -accepteula -e \\" & strComputer & " cmd /c dir /s /b " & arrDrives(intCount) & ":\  >> " & strOutputFile
                  objShell.Run strCommand, 0, True
            Next
            
      Else
            MsgBox "Could not ping " & strComputer
      End If
Wend

objShell.Run "notepad " & strOutputFile, 1, False
MsgBox "Done"
WScript.Quit

'************* PING FUNCTION ********************
Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'***********************************
'=================

P.S.  I will change the script that deletes files for the other question later.......

Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 19562558
This script when i run.It just asks me for the Drives.When i give a drive "D" without qotes it says done that's it.No other output.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19562582
Do you see the Notepad document coming up?  That should happen when it gets to this line:
objShell.Run "notepad " & strOutputFile, 1, False

Which launches Notepad (the same as clicking Start --> Run, type
notepad
and press Enter.

See if you can run
notepad "C:\Temp\Test.txt"
as long as that file exists, and if so, this should work.

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19562835
As we discovered in the other question you were asking, the problem was that you needed to change the path pointing to PSExec, otherwise it could not run the remote process.

Thanks Sharath,

Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 19562866
Change the path as this.

 I forgot to mention you will need to change this part
strCommand = "cmd /c \\mccdc01\netlogon\psexec_182.exe ........

which specifies the path to PSExec....Sorry!

If you have PSExec in the same path as the script file, just change the above to
strCommand = "cmd /c psexec.exe ........

And it worked....
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

830 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