Network Info / inventory
- Creates an Excel File with the Network Info / inventory of all the computers that are listed in servers.txt
- Needs Excel to be installed on the machine that the script will be run from.
Queries and reports the listed items:
Machine Name [Which is provided in the Servers.txt]
Status
NIC Label
IP Address
Subnet Mask
Default Gateway
MAC Address
DNS Servers
WINS Servers
WINS Servers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
'========================================================================== ' VBScript Network Inventory ' NAME: Network_Inventory.vbs ' AUTHOR: Murali Palla ' Contact contact@muralipalla.com ' DATE : 5/4/2013 ' Creates an Excel File with the Network Info / inventory of all the computers that are listed in servers.txt ' Needs Excel to be installed on the machine that the script will be run from. '========================================================================== ScriptStartTime = Now() Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("WScript.Shell") If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False WScript.Quit End If If not objFSO.FileExists("servers.txt") Then wscript.echo "Please create a file named 'servers.txt' with one Server name per line," wscript.quit End If Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True objExcel.Workbooks.Add intRow = 2 objExcel.Cells(1, 1).Value = "Machine Name" objExcel.Cells(1, 2).Value = "Status" objExcel.Cells(1, 3).Value = "NIC Label" objExcel.Cells(1, 4).Value = "IP Address" objExcel.Cells(1, 5).Value = "Subnet Mask" objExcel.Cells(1, 6).Value = "Default Gateway" objExcel.Cells(1, 7).Value = "MAC Address" objExcel.Cells(1, 8).Value = "DNS Servers" objExcel.Cells(1, 9).Value = "WINS Servers" objExcel.Cells(1, 10).Value = "WINS Servers" objExcel.Cells.EntireColumn.AutoFit objExcel.Range("A1:I1").Select objExcel.Selection.Interior.ColorIndex = 19 objExcel.Selection.Font.ColorIndex = 11 objExcel.Selection.Font.Bold = True WScript.Echo "Script Started, You will be notified once complete... Please be patient." tempobj="temp.txt" Set objTextFile = objFSO.OpenTextFile("servers.txt", 1) strText = objTextFile.ReadAll objTextFile.Close arrComputers = Split(strText, vbCrLF) for each item in arrcomputers WScript.Echo item objShell.Run "cmd /c ping -n 1 -w 1000 " & item & " >temp.txt", 0, True Set tempfile = objFSO.OpenTextFile(tempobj,1) Do Until tempfile.AtEndOfStream temp=tempfile.readall striploc = InStr(temp,"[") If striploc=0 Then strip="" Else strip=Mid(temp,striploc,16) strip=Replace(strip,"[","") strip=Replace(strip,"]","") strip=Replace(strip,"w"," ") strip=Replace(strip," ","") End If If InStr(temp, "Reply from") Then strMStatus = "Success" callf = GetIPDetails(item,strMStatus,strip) ElseIf InStr(temp, "Request timed out.") Then strMStatus = "RTO" callf = GetIPDetails(item,strMStatus,strip) ElseIf InStr(temp, "try again") Then strMStatus = "NDS" callf = GetIPDetails(item,strMStatus,strip) End If Loop Next intRow = intRow + 2 objExcel.Cells(intRow, 3).Value = "Script Start Time" objExcel.Cells(intRow, 4).Value = ScriptStartTime intRow = intRow + 1 objExcel.Cells(intRow, 3).Value = "Script Completed At" objExcel.Cells(intRow, 4).Value = Now() objExcel.Cells.EntireColumn.AutoFit strScriptName=WScript.ScriptName strFullPath = WScript.ScriptFullName strFileCompleteDate = Replace(Replace(Replace(Now(),"/","_"),":","_")," ","_") strPath=Replace(strFullPath,strScriptName,"")&replace(strScriptName,".vbs","")&"_"&strFileCompleteDate&".xlsx" objExcel.ActiveWorkbook.Saveas strPath objExcel.ActiveWorkbook.Close tempfile.close objfso.deletefile(tempobj) Wscript.Echo "Done" '*************** Functions Start ******************************************************************************************************* Function GetIPDetails(strComputer,strStatus,pingip) On Error Resume Next If strStatus = "Success" Then 'WScript.Echo vbTab &vbTab &"Checking DSM.OPT" 'DSMOPT=readfile(strComputer) Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CimV2") Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IpEnabled = True" ) If Err.Number Then WScript.Echo vbTab &vbTab &"Unable to Establish a WMI Session, Error: " &Err.Number &vbTab &Err.Description objExcel.Cells(intRow, 1).Value = strComputer objExcel.Cells(intRow, 2).Value = "Online." objExcel.Cells(intRow, 3).Value = pingip objExcel.Cells(intRow, 4).Value = Err.Number objExcel.Cells(intRow, 5).Value = Err.Description intRow = intRow + 1 Else WScript.Echo vbTab &vbTab &"Checking Network INFO" For Each objItem in colItems strIpAddress = Join(objItem.IpAddress,";") strIpSubnet = Join(objItem.IpSubnet,";") strDNSDomain = Join(objItem.DNSServerSearchOrder,";") strDefaultGateway = Join(objItem.DefaultIpGateway,";") If strDefaultGateway <> "" Then objExcel.Cells(intRow, 1).Value = UCase(objItem.DnsHostName) objExcel.Cells(intRow, 2).Value = "Online." objExcel.Cells(intRow, 3).Value = AdapterName(objItem.Caption) objExcel.Cells(intRow, 4).Value = strIPAddress strIPAddress=Null objExcel.Cells(intRow, 5).Value = strIPSubnet strIPSubnet=Null objExcel.Cells(intRow, 6).Value = strDefaultGateway strDefaultGateway=Null objExcel.Cells(intRow, 7).Value = objItem.MacAddress objExcel.Cells(intRow, 8).Value = strDNSDomain strDNSDomain=Null objExcel.Cells(intRow, 9).Value = objItem.WINSPrimaryServer objExcel.Cells(intRow, 10).Value = objItem.WINSSecondaryServer intRow = intRow + 1 Else End If Next End If ElseIf strStatus = "RTO" Then WScript.Echo vbTab &vbTab &"No response (Offline)." objExcel.Cells(intRow, 1).Value = strComputer objExcel.Cells(intRow, 2).Value = "No response (Offline)." objExcel.Cells(intRow, 4).Value = pingip intRow = intRow + 1 ElseIf strStatus = "NDS" Then WScript.Echo vbTab &vbTab &"Unknown host (no DNS entry)." objExcel.Cells(intRow, 1).Value = strComputer objExcel.Cells(intRow, 2).Value = "Unknown host (no DNS entry)." objExcel.Cells(intRow, 4).Value = pingip intRow = intRow + 1 End If End Function Function AdapterName(strAdapter) Dim colItems,objItem,ObjWMIService Set ObjWMIService = GetObject("winmgmts:\\" & item & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter where caption ='"&strAdapter&"'",,48) For Each objItem in colItems AdapterName = objItem.NetConnectionID Next End Function Function readfile(strComputer) Dim objFSO,strDSMOPT,strLine,strReadInput Set objFSO = CreateObject("Scripting.FileSystemObject") strReadInput= "\\"&strComputer&"\c$\Program Files\Tivoli\TSM\baclient\dsm.opt" If objFSO.FileExists(strReadInput) Then Set strDSMOPT = objFSO.OpenTextFile(strReadInput, 1) WScript.Sleep (1000) Do Until strDSMOPT.AtEndOfStream strLine=ucase(strDSMOPT.ReadLine) If InStr(strLine,"*") Then ElseIf InStr(strLine,"TCPSERVERADDRESS") Then readfile = trim(Mid(strLine,18,20)) strDSMOPT.Close Exit Function End If Loop readfile="Not Able to Find TCPSERVERADDRESS" strDSMOPT.Close WScript.Sleep(2000) Else readfile="Not Able to Find: "&strReadInput End If End Function '*************** Functions End ******************************************************************************************************* |
1,996 total views, 2 views today
Leave a Reply
You must be logged in to post a comment.