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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script that checks for folders on remote servers

Status
Not open for further replies.

ms77ao

Technical User
Nov 26, 2007
4
Hi
Just wondering if is it possible to write a script that will check to see if a folder exist on it. If the folder does not exist then the computer name of the server should be exported to a csv file. I am having trouble with getting it to iterate the checking process of multiple domain controllers and then exporting the information to the csv. Any ideas or suggestions would be appreciated.

Set objFSO = CreateObject("Scripting.FileSystemObject")

strComputer = "ukdc0185"

If objFSO.FolderExists("\\" & strComputer & "\c$\program files\Veritas")Then
Wscript.echo "Backup exec installed"
Else
Wscript.Echo "Veritas folder does not exist."
End If
 
Try posting in a vbscript forum. Somthing like this

Code:
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set f = objFSO.CreateTextFile ("C:\ExistFolder.csv", ForAppending)
strComputer = "192.168.4.125;192.168.4.1;192.168.4.6;MachineName"
searchDir = "C:\backup"
aMachines = split(strComputer, ";")
For Each machine In aMachines
  Set objPing = GetObject("winmgmts:")._
      ExecQuery("select * from Win32_PingStatus where address = '"_
      & machine & "'")
  For Each objStatus In objPing
      If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
          WScript.Echo("machine " & machine & " is not reachable")
      Else 
	  Call Search
          WScript.Echo("reply from " & machine)   
      End If
  Next
Next

Function Search
	If  objFSO.FolderExists( strMachine & searchDir)Then
			Wscript.echo "Backup exec installed"
			f.writeline Machine & searchdir & "exists"
		Else
			f.writeline Machine & "Veritas folder does not exist." & vbcrlf
	End If 
end function
MsgBox "done"
 
faq329-4871

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.
 
Hi
I have almost got this work. it does echo out the results but need it write to an excel sheet next to the servers in the attached spreadsheet. If anyone has hints or suggestions it would be very much appreciated. I am having trouble attaching the spreadsheet but also it has in the first and second cells are names of servers.

On Error Resume Next


Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")

x = 1
y = 1

Do Until objExcel.Cells(x, 1).Value = ""
If objExcel.Cells(x, 1).Value = "" Then
Exit Do
End If

strComputer = objExcel.Cells(x, 1).Value

If objFSO.FolderExist("\\" & strComputer & "\c$\Veritas")Then

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(y, 2).Value = "Backupexec installed "

'Wscript.echo strcomputer & " Backup exec installed"

Else

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(y, 2).Value = "Backupexec not installed"

'Wscript.Echo strcomputer & " Veritas folder does not exist."

End If


x = x + 1
y = y + 1
Loop

objWorkbook.Close
objExcel.Quit

Regards
Sunil
 
You were close.

Code:
On Error Resume Next


Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")
objExcel.Visible = True
objExcel.Workbooks.Add

xlrow = 1

Do Until objExcel.Cells(xlrow, 1).Value = ""

    strComputer = objExcel.Cells(xlrow, 1).Value 
    
    If objFSO.FolderExist("\\" & strComputer & "\c$\Veritas")Then 
	    objExcel.Cells(xlrow, 2).Value = "Backupexec installed " 
		'Wscript.echo strcomputer &  " Backup exec installed" 
    Else 
	    objExcel.Cells(xlrow, 2).Value = "Backupexec not installed"
  	    'Wscript.Echo strcomputer &  " Veritas folder does not exist." 
    End If 
	xlrow = xlrow + 1
Loop

objWorkbook.Close
objExcel.Quit

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.
 
ms77ao,

So did the code I provided help?

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.
 
Hi Mark
For some reason it would not write to the excel file. As I mentioned before I can get it to echo out the results but still won't write it to the excel file. I tried to upload the excel sheet but would not let me. It looks something like this

Cell1 cell2
UKDC0100 Yes
UKDC0128 No

as you mentioned I am close but not quite there. I do appreciate your help.

Regards
Sunil
 
Sorry must have been a really late night for me not to have caught a few things here.

First off are you trying to start with an existing spreadsheet that already has computer names in it? If so then you need to modify the code as such:

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = GetObject(,"Excel.Application")
objExcel.Visible = True

xlrow = 1

Do Until objExcel.Cells(xlrow, 1).Value = ""

    strComputer = objExcel.Cells(xlrow, 1).Value 
    
    If objFSO.FolderExist("\\" & strComputer & "\c$\Veritas")Then 
        objExcel.Cells(xlrow, 2).Value = "Backupexec installed " 
        'Wscript.echo strcomputer &  " Backup exec installed" 
    Else 
        objExcel.Cells(xlrow, 2).Value = "Backupexec not installed"
          'Wscript.Echo strcomputer &  " Veritas folder does not exist." 
    End If 
    xlrow = xlrow + 1
Loop

objExcel.Quit

note that the above will bind to whatever Excel spreadsheet is already open, so close all other spreadsheets and just open the one you have with your machine names in the first column.

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.
 
Hi
Thanks for your help. The script works a charm. Thank you for your persistance.

Regards
Sunil
 
You are welcome. Always happy to help.

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