We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
'—– Let's Dim our variables —————————————————————- Dim strComputer, objFSO '—– Set some constants used for manipulating text files————————————- Const ForReading = 1 Const ForAppending = 8 '—– Let's open the list of workstations we grabbed from Active Directory ——————- Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\Scriptomatic2\workstations.txt", ForReading) '—– We want to loop through the text file line by line, grabbing MAC addresses as we go — Do Until objFile.AtEndOfStream strComputer = objFile.ReadLine '—– Let's see if we can ping the workstation ———————————————– Set WshShell = CreateObject("WScript.Shell") PINGFlag = Not CBool(WshShell.run("ping -n 2 -w 250 " & strComputer,0,True)) '—– If we can ping the workstation, grab the MAC address and save it in a text file ——– If PINGFlag = True Then wScript.Echo strComputer & " pings" Dim objShell,objExec Set objShell=CreateObject("wscript.shell") strCommand="nbtstat -a " & strComputer Set objExec=objShell.Exec(strCommand) Do While objExec.StdOut.AtEndOfStreamTrue strLine=objExec.StdOut.ReadLine If InStr(strLine,"MAC Address") Then arrFields = Split(strLine, " ") strMAC1 = arrFields(7) strMACAddress = Replace(strMAC1, "-", "") strCompEntry = strComputer & "," & strMACAddress Set objFile2 = objFSO.OpenTextFile("C:\Scriptomatic2\MAC_Addresses.txt", ForAppending) objFile2.WriteLine strCompEntry objFile2.close End If Loop Else '—– If we can't ping the workstation, let's log that so we can get the MAC address later —- Set objFile3 = objFSO.OpenTextFile("C:\Scriptomatic2\cannot_ping.txt", ForAppending) objFile3.WriteLine strComputer objFile3.close End If Loop
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.