Re: finding files

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"capt edgar" <captedgar@xxxxxxxxxxxxxx> wrote in message
news:adefaf30-9282-474b-9a34-bbeae5332992@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi there

I'm a newbie to programming but very much willing to work hard and
try. We have about 100 servers and on each servers we have the g drive
and e drive. early this year there were some temp files dumped all
over the 100 servers under variuos folders and subfolders so i have
been assigned a task to clean this up. Any chance someone can guide me
in getting an automated script where all i need to do is enter the
list of servers and the file extension to search and then script would
scan for the file extension on all 100 servers and each of the drives
associated with it.

so far i have the following script


Rem Script created: 01.10.2009 22:24
Rem Author: captedgar

strDir = "c:\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
If LCase(Right(CStr(aItem.Name), 3)) = "tmp" Then
'wscript.Echo aItem.Name 'all c:\*.tmp
listed
End If
Next
For Each aItem In pCurrentDir.SubFolders
getInfo(aItem) 'passing recursively
Next

End Sub

Your code will work very nicely, stepping recursively through all folders on
the specified drive. To make it go through all existing drives you could use
the following code:

Const Fixed = 2

Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oDrive In oFSO.Drives
If oDrive.DriveType = Fixed _
Then getInfo oFSO.GetFolder(oDrive.DriveLetter & ":\")
Next

Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
If LCase(Right(CStr(aItem.Name), 3)) = "tmp" _
Then WScript.Echo aItem.Name 'all c:\*.tmp listed
Next
For Each aItem In pCurrentDir.SubFolders
getInfo(aItem) 'passing recursively
Next
End Sub

If you wish to deal with several file extensions then you have to repeat the
process for each extension.

While it would be fairly straightforward to process a list of x servers with
a script running on your own machine, execution would be very slow and you
would choke your network for many hours. This is because the script must
read hundreds of thousands of file names from each server. It would be much
fast to execute the script locally on each server, e.g. like so:

@echo off
for /F %%a in (c:\Servers.txt) do (
psexec.exe -u edgar -p password \\%%a \\YourPC\c$\script.vbs
)

This batch file will do the following:
- It will enumerate your server names from c:\Servers.txt
- It will start a console session at each server, using the
specified user name and password.
- It will invoke the script that you keep on your own machine.

Note that the script represents a security risk because your
account/password is hard coded and visible to anyone working on your
machine.

You can download psexec.exe from www.sysinternals.com.


.



Relevant Pages

  • Re: Deny rules...
    ... services client I have not implemented it. ... Tony Su ... >The Script makes sure the ip to be blocked is not itīs ... >I have few outside servers to connect from to my servers ...
    (microsoft.public.isa)
  • Re: finding files
    ... We have about 100 servers and on each servers we have the g drive ... list of servers and the file extension to search and then script would ... For Each aItem In pCurrentDir.SubFolders ... To make it go through all existing drives you could ...
    (microsoft.public.scripting.vbscript)
  • Re: Software configuration management tool required
    ... If it automates ... and 100-ish servers, it's just not going to happen. ... you test it by running the rc?.d script that init will ... > because Oracle or some vendor tells them to do so. ...
    (comp.unix.admin)
  • Re: Mapping Drive Question
    ... that when the client is started maps the appropriate servers as network ... drives and initiates the application. ... In the script I use the "false" option not to add to the user profile so ...
    (microsoft.public.scripting.vbscript)
  • Drive Mapping issue - Please HELP
    ... When people login to their desktops the script works fine but they ... have issues when the sign into the terminal servers. ... We delete the cached profiles after 5 minutes and just ... nothing fancy at all just mapping a few drives. ...
    (microsoft.public.windows.terminal_services)