If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.
'—– 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
Join the community of 500,000 technology professionals and ask your questions.