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

Looping through an array

Status
Not open for further replies.

SSAGuyOR

MIS
Joined
Mar 2, 2006
Messages
4
Location
US
I am hoping that the real vbscript experts here can help with a problem I am having. I have a script that I gleaned and the subsequently altered that checks Windows servers for some "things" and then writes the results to a web page that the script creates. I used the IP address of the servers due to the fact that we do not have DNS host names for the servers. What I discovered was that the IP address is not informative enough so I wanted to assign another array with the names I have assigned to the servers. At one point in the script, there is a variable declaration that used the IP address array created before. I wanted to use a different variable (which I defined, but obviously not correctly or I wouldn't be here asking for help) that pulled the machine names I specified in the other Array, but all I get is the first name in the array over and over again. Below is a portion of my script that defines the array with the IP address. This works and displays the IP address for each machine as the page is built:

Code:
'User defined Variables - Modify as needed
CurrentDate = Now
company = "Company Name"
servers = Array("170.134.10.85","170.144.31.25","10.10.143.75","10.10.108.174","10.10.104.74","10.10.106.171","10.10.102.71")
sysnames = Array("oisterweb2k3","WrrRS2K3BPRD","WrS2K3WEBDEV","WRVOWCA2KRPT","WcvRVOWCA2KPRD","WcRCA2KDEV","WcvCA2KACT")
resultsfile = "c:\" & FormatDateTime(CurrentDate, vbLongDate) & ".htm "
'Key path is designed only for Tivoli Storage
strKeyPath = "SOFTWARE\IBM\ADSM\CurrentVersion\AdminClient"
strValueName = "PtfLevel"
strValueData = ""

'System variables - DO NOT CHANGE
Const HKEY_LOCAL_MACHINE = &H80000002
ForWriting = 2
forReading = 1
forWriting = 2
forAppending = 8

CutOff = Date() - 1

Set fs = WScript.CreateObject("Scripting.FileSystemObject")

'Create the htm file with header
Set res = fs.CreateTextFile(resultsfile, True)
res.Writeline ("<html>")
res.Writeline ("<br>")
res.Writeline ("<h2>Server Summary for " & company & " on: <font color='#000080'>" & date() & "</font></h2>")

'Loop through the array of servers
'Perform checks on each server
For each server in servers
strserver = server
checks(strserver)
Next

The code that writes part of the web page is this:

Code:
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk where DriveType = 3")

res.Writeline ("<table BORDER=1 width=100% cellspacing=0 cellpadding=1>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=#000080 colspan=3 width=100%>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=Verdana size=3 color=#FFFFFF>System Summary for " & strserver & "</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=#C0C0C0 width=11% align=left><font face=Verdana color=#000080 size=1>Disk ID</font></th>")
res.Writeline ("<th bgcolor=#C0C0C0 width=16% align=left><font face=Verdana color=#000080 size=1>Percentage Free Space</font></th>")
res.Writeline ("<th bgcolor=#C0C0C0 align=left><font face=Verdana color=#000080 size=1>Free Space</font></th>")
res.Writeline ("</tr>")

This works and displays "System Summary for xxx.xxx.xxx.xxx" which is cool, but I want to pull the machine name from an array and use that instead of the IP address which is pulled from the first array, so it would look like this: "System summary for oisterweb2k3".

I hope I explained this correctly, but it is complicated (at least for me). Anybody understand what I am trying to do and feel like helping?
 
Replace this:
For each server in servers
strserver = server
checks(strserver)
Next
with this:
For i = 0 To Ubound(servers)
checks servers(i), sysnames(i)
Next

And add a 2nd argument (the server name) in the declaration of your checks Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you for the help. Like this?

Code:
'Loop through the array of servers
'Perform checks on each server
For i = 0 To Ubound(servers)
  checks servers(i), sysnames(i)
Next

'Script complete
res.Writeline ("</html>")

'//////////////////
'FUNCTIONS
'//////////////////

'Entry point for server checks
Function checks (strserver,sysnames)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top