Option Explicit Dim cn Dim rs, ToAddress, ResultInMail, ResultToFile, strOutFilePath Dim fld, fldValue Dim cmdText, StrOut, strTD Dim fso, strOutFile Const MailServerName = "smarthost.dns.microsoft.com" Const SMTPTimeout = 10 Const FromAddress = "ghtools@microsoft.com" Const CCAddress = "" Const cdoSendUsingPort = 2 Const TristateTrue = -1 Const TristateFalse = 0 Const TristateUseDefault = -2 Const Indent = " " Const strQuery = "select * from vwReachability order by devicename" Const TableTitle = "Devices that failed reachability test" Const ReportTitle = "IHS Device Reachability Report" ToAddress = "" strOutFilePath ="" ResultInMail = false ResultToFile = false Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") Set fso = CreateObject("Scripting.FileSystemObject") Sub Main() Dim arg1, arg2 arg1="" arg2="" If wscript.arguments.count > 0 Then arg1 = wscript.arguments(0) Else wscript.echo "Neither email address or file path provided." wscript.echo "One or both needs to be provided so results are saved." wscript.echo "Exiting..." wscript.quit End If If wscript.arguments.count > 1 Then arg2 = wscript.arguments(1) End If If InStr(1,arg1,"@")=0 Then wscript.echo "Found File Name in arg1" strOutFilePath = arg1 Else wscript.echo "Found Email Address arg1" ToAddress = arg1 End If If arg2 <> "" Then If InStr(1,arg2,"@")=0 Then strOutFilePath = arg2 wscript.echo "Found File Name in arg2" Else wscript.echo "Found Email Address arg2" ToAddress = arg2 End If End If wscript.echo "File Path = " & strOutFilePath wscript.echo "ToAddress = " & ToAddress If ToAddress <> "" Then ResultInMail=True If strOutFilePath <> "" Then ResultToFile=True wscript.echo "ResultInMail = " & ResultInMail wscript.echo "ResultToFile = " & ResultToFile 'Set ADO connection properties. cn.Provider = "sqloledb" cn.Properties("Data Source").Value = "ineteng" cn.Properties("Initial Catalog").Value = "network" 'cn.Properties("User ID").Value = "" 'cn.Properties("Password").Value = "" cn.Properties("Integrated Security").Value = "SSPI" cn.Open wscript.echo "Creating Report headers" 'Create HTML headers strOut = "" & vbcrlf strout = strout & "
" & vbcrlf strout = strout & "" & fld.name & " | " & vbcrlf Next strout = strout & indent & "||||
" Case 4,5 ' Numeric fldValue = FormatPercent (rs.fields(x).value,2,TristateTrue,TristateFalse,TristateTrue) If IsNull(fldValue) Then fldvalue = 0 strTD= " | "
Case 200 'String
fldValue = Trim(rs.fields(x).value)
If fldValue="" or IsNull(fldValue) Then
'wscript.echo "empty string replaced with space"
fldvalue = " " End If If IsNumeric(fldvalue) Then strTD= " | " Else strTD= " | " End If Case Else fldValue = rs.fields(x).value strTD= " | " End Select If fldValue = "zTotal" Then fldValue = "Total" strout = strout & indent & indent & strTD & fldValue & " | " & vbcrlf Next strout = strout & indent & "