Vbs Script To Enumerate A Subnet Range And Determine Which Machines Are SMS Clients

 

Use this Vbs script to enumerate a subnet range or range of IP addresses to determine which machines are or are not SMS clients and send the results to Excel. It will also attempt to determine the IP address and Machines Name for each IP address as well.

 

Note: The Subnet range must have the following syntax xxx.xxx.xxx. with the trailing “.” at the end of the first Input box prompt.

 

To make the script input boxes easier to understand I have added examples for each and the input box will be auto populated with them Change them as needed.

 

Vbs Script:

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "IP Address"

objExcel.Cells(1, 2).Value = "Machine Name"

objExcel.Cells(1, 3).Value = "SMS Client"

 

strSubnet = InputBox("Enter Subnet Range", "strSubnet", "192.168.1.")

intStartingAddress = InputBox("Enter Start Address", "intStartingAddress", "0")

intEndingAddress = InputBox("Enter End Address", "intEndingAddress", "255")

 

For i = intStartingAddress to intEndingAddress

strTarget = strSubnet & i

 

Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._

ExecQuery("select Replysize from Win32_PingStatus where address = '" & strTarget & "'")

 

For Each objItem in objPing

If IsNull(objItem.ReplySize) Then

IsConnectible = False

Else

 

On Error Resume Next

 

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strTarget & "\root\cimv2")

Set colCompSystems = objWMIService.ExecQuery("Select * From " & "Win32_ComputerSystem")

For Each objCompSystem In colCompSystems

objExcel.Cells(intRow, 1).Value = strTarget

objExcel.Cells(intRow, 2).Value = UCase(objCompSystem.Name)

Next

 

Set objWMIService = GetObject("winmgmts://" & strTarget & "/root/ccm")

Set colItems = objWMIService.ExecQuery("Select * from Sms_Client")

If Err.Number = 0 Then

objExcel.Cells(intRow, 3).Value = "YES"

intRow = intRow + 1

Else

objExcel.Cells(intRow, 3).Value = "NO"

intRow = intRow + 1

End If

End If

Next

 

objExcel.Range("A1:C1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

Next

 

Set objExcel = Nothing

Set objPing = Nothing

Set objWMIService = Nothing

Set colCompSystems = Nothing

Set smsClient = Nothing

 

Wscript.Echo "Done"

Published Sunday, November 26, 2006 4:47 PM by dhite
Filed under:

Comments

No Comments