[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

Collect Ethernet Adapter Wireless Network MAC address

I need help to collect Ethernet Adapter Wireless Network MAC address for a list of laptops. I will have an input file with all the Service Tag of the laptops in there. I need a VB Script that will read through the input file and export the following to a text or excel file

Service Tag & Ethernet Adapter Wireless Network MAC address

Eg  The output file will look like
23N7V1S    00-1F-3B-01-49-BD
CZNS22S   00-22-FB-CD-4A-18

Thanks
Cheers



0
Bianchi928
Asked:
Bianchi928
  • 5
  • 3
  • 2
1 Solution
 
spinzr0Commented:
If you have admin access to all of the PCs then you can use WMI as in the example below.
On Error Resume Next

sInputFile = "Input.txt"
sOutputFile = "Output.csv"
sAdminUserName = "username"
sAdminPassword = "password"

Set oFS = CreateObject("Scripting.FilesystemObject")

Set oInputFile = oFS.OpenTextFile(sInputFile, 1, True)
Set oOutputFile = oFS.CreateTextFile(sOutputFile, True)

sSerialQuery = "Select IdentifyingNumber From Win32_ComputerSystemProduct"
sWiFiQuery = "Select MACAddress from Win32_NetworkAdapterConfiguration WHERE Description Like '%WiFi%' OR Description Like '%Wireless%' OR Description Like '%AGN%'"

Set oComputerObject = CreateObject("WbemScripting.SWbemLocator")
oComputerObject.Security_.ImpersonationLevel = 3
oComputerObject.Security_.AuthenticationLevel = 0

Do While Not oInputFile.AtEndOfStream
    sPC = oInputFile.ReadLine
    Set oWMI = oComputerObject.ConnectServer(sPC, "root\cimv2", sPC & "\" & sAdminUserName, sAdminPassword)

    Set cTemp1 = oWMI.ExecQuery(sSerialQuery)
    Set cTemp2 = oWMI.ExecQuery(sWiFiQuery)
    For Each oItem In cTemp1
        oOutputFile.Write oItem.IdentifyingNumber & ","
    Next
    For Each oItem In cTemp2
        oOutputFile.WriteLine oItem.MACAddress
        Exit For
    Next
    Set cTemp1 = Nothing
    Set cTemp2 = Nothing
    Set oWMI = Nothing
Loop
Set oComputerObject = Nothing
Wscript.Echo "Complete."

Function Ping(sHost)
    Dim oWMILocal, cPings, oPing, iPingResult

    Set oWMILocal = GetObject("winmgmts:\\.\root\cimv2")

    Set cPings = oWMILocal.ExecQuery("Select * from Win32_PingStatus " &_
        "Where Address = '" & sHost & "' AND timeout = 500")
    For Each oPing In cPings
        iPingResult = oPing.StatusCode
        If (iPingResult = 0) Then
            Ping = True
            Exit Function
        Else
            Ping = False
        End If
    Next
End Function

Open in new window

0
 
WaseemsCommented:
check this script you might, I don't have wireless network card on my computer to check it but you might need to change line 51 if it didn't work remove  WHERE AdapterType like '%wireless%' from the code and try it I thing adaptertype should be wireless but you can try it
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strOutputDir, strOutputFile, strComputersList 
On Error Resume Next

Const ForAppending = 8
Const ForReading = 1

'Variables to change
strOutputDir = "d:\desktop"	'folder to store outputfile should be written without end \
strOutputFile = "output.txt"	'file to store output data should start with \
strComputersList = "d:\desktop\ServerList.txt"


Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strOutputDir) Then
   Set objFolder = objFSO.GetFolder(strOutputDir)
Else
   Set objFolder = objFSO.CreateFolder(strOutputDir)
End If

If objFSO.FileExists(strOutputDir & "\" & strOutputFile) Then
   Set objFolder = objFSO.GetFolder(strOutputDir)
Else
   Set objFile = objFSO.CreateTextFile(strOutputDir & "\" & strOutputFile)
End If 

set objFile = nothing
set objFolder = nothing

Set objTextFile = objFSO.OpenTextFile (strOutputDir & "\" & strOutputFile, ForAppending, True)



Set objFile = objFSO.OpenTextFile(strComputersList, ForReading)
Do Until objFile.AtEndOfStream

strComputer = objFile.ReadLine 
tLine = strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 

select case err.number
  case 0
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure",,48) 
    For Each objItem in colItems 
        tLine= tLine & vbtab & objItem.SerialNumber
    Next

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE AdapterType like '%wireless%'",,48) 

    For Each objItem in colItems 
        if objItem.MACAddress <>"" then tLine= tLine & vbtab & objItem.AdapterType & " (" objItem.MACAddress & ")"
    Next
  case 70
    tLine=tLine & vbtab & "Access denied"
  case 462
    tLine=tLine & vbtab & "Cannot be Contacted"
  case else
    wscript.echo err.number
end select

  objTextFile.WriteLine(tLine)
   
  strComputer = Null
  objWMIService = Null
  colItems = Null
  objItem = Null

Loop
objFile.Close

objTextFile.Close
wscript.echo "Script execution Completed, check the file " & strOutputDir & "\" & strOutputFile & " for output results"

Open in new window

0
 
Bianchi928Author Commented:
spinzr0:

it's almost there...Here's the content of my input file

745362S
9P7HR1S
B45362S
5H1VY1S
155362S

and the following is my output file

745362S      00:23:14:A8:A4:08
00:23:14:A8:A4:08      
B45362S      00:23:14:A8:63:88
00:23:14:A8:63:88      
155362S      00:23:14:A5:DE:A4

As you can see it repeats the Mac address of the previous because the laptops 9P7HR1S & 5H1VY1S were turned off.

I would rather see the output look like the following

745362S      00:23:14:A8:A4:08
9P7HR1S      Not Found
B45362S      00:23:14:A8:63:88
5H1VY1S      Not Found
155362S      00:23:14:A5:DE:A4

Thanks
Cheers



0
Industry Leaders: We Want Your Opinion!

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!

 
spinzr0Commented:
Give this a shot
On Error Resume Next

sInputFile = "Input.txt"
sOutputFile = "Output.csv"
sAdminUserName = "username"
sAdminPassword = "password"

Set oFS = CreateObject("Scripting.FilesystemObject")

Set oInputFile = oFS.OpenTextFile(sInputFile, 1, True)
Set oOutputFile = oFS.CreateTextFile(sOutputFile, True)

sSerialQuery = "Select IdentifyingNumber From Win32_ComputerSystemProduct"
sWiFiQuery = "Select MACAddress from Win32_NetworkAdapterConfiguration WHERE Description Like '%WiFi%' OR Description Like '%Wireless%' OR Description Like '%AGN%'"

Set oComputerObject = CreateObject("WbemScripting.SWbemLocator")
oComputerObject.Security_.ImpersonationLevel = 3
oComputerObject.Security_.AuthenticationLevel = 0

Do While Not oInputFile.AtEndOfStream
    sPC = oInputFile.ReadLine
    Err.Clear
    Set oWMI = oComputerObject.ConnectServer(sPC, "root\cimv2", sPC & "\" & sAdminUserName, sAdminPassword)
    If Err.Number <> 0 Then
        oOutputFile.WriteLine sPC & ",Not Found"
        Err.Clear
    Else
        Set cTemp1 = oWMI.ExecQuery(sSerialQuery)
        Set cTemp2 = oWMI.ExecQuery(sWiFiQuery)
        For Each oItem In cTemp1
            oOutputFile.Write oItem.IdentifyingNumber & ","
        Next
        For Each oItem In cTemp2
            oOutputFile.WriteLine oItem.MACAddress
            Exit For
        Next
        Set cTemp1 = Nothing
        Set cTemp2 = Nothing
    End If
    Set oWMI = Nothing
Loop
Set oComputerObject = Nothing
Wscript.Echo "Complete."

Function Ping(sHost)
    Dim oWMILocal, cPings, oPing, iPingResult

    Set oWMILocal = GetObject("winmgmts:\\.\root\cimv2")

    Set cPings = oWMILocal.ExecQuery("Select * from Win32_PingStatus " &_
        "Where Address = '" & sHost & "' AND timeout = 500")
    For Each oPing In cPings
        iPingResult = oPing.StatusCode
        If (iPingResult = 0) Then
            Ping = True
            Exit Function
        Else
            Ping = False
        End If
    Next
End Function

Open in new window

0
 
Bianchi928Author Commented:
spinzr0:

Since it was weekend, I gave it a shot this morning and the following is the result..It seems that "spc" is not returning any value (service tag).

,Not Found
,Not Found
,Not Found
,Not Found
1R43T1S,00:1C:BF:8B:7F:CF
,Not Found
,Not Found
DMSDT1S,00:1D:E0:79:A5:75

Cheers
Christian

0
 
WaseemsCommented:

have you tried my code or spinzr0
0
 
spinzr0Commented:
sPC is just the read in line.  Does the input file ahve blank lines?  I've added a messagebox so you can see as it reads in if its getting valid data.
On Error Resume Next

sInputFile = "Input.txt"
sOutputFile = "Output.csv"
sAdminUserName = "username"
sAdminPassword = "password"

Set oFS = CreateObject("Scripting.FilesystemObject")

Set oInputFile = oFS.OpenTextFile(sInputFile, 1, True)
Set oOutputFile = oFS.CreateTextFile(sOutputFile, True)

sSerialQuery = "Select IdentifyingNumber From Win32_ComputerSystemProduct"
sWiFiQuery = "Select MACAddress from Win32_NetworkAdapterConfiguration WHERE Description Like '%WiFi%' OR Description Like '%Wireless%' OR Description Like '%AGN%'"

Set oComputerObject = CreateObject("WbemScripting.SWbemLocator")
oComputerObject.Security_.ImpersonationLevel = 3
oComputerObject.Security_.AuthenticationLevel = 0

Do While Not oInputFile.AtEndOfStream
    sPC = oInputFile.ReadLine
    Msgbox sPC
    Err.Clear
    Set oWMI = oComputerObject.ConnectServer(sPC, "root\cimv2", sPC & "\" & sAdminUserName, sAdminPassword)
    If Err.Number <> 0 Then
        oOutputFile.WriteLine sPC & ",Not Found"
        Err.Clear
    Else
        Set cTemp1 = oWMI.ExecQuery(sSerialQuery)
        Set cTemp2 = oWMI.ExecQuery(sWiFiQuery)
        For Each oItem In cTemp1
            oOutputFile.Write oItem.IdentifyingNumber & ","
        Next
        For Each oItem In cTemp2
            oOutputFile.WriteLine oItem.MACAddress
            Exit For
        Next
        Set cTemp1 = Nothing
        Set cTemp2 = Nothing
    End If
    Set oWMI = Nothing
Loop
Set oComputerObject = Nothing
Wscript.Echo "Complete."

Function Ping(sHost)
    Dim oWMILocal, cPings, oPing, iPingResult

    Set oWMILocal = GetObject("winmgmts:\\.\root\cimv2")

    Set cPings = oWMILocal.ExecQuery("Select * from Win32_PingStatus " &_
        "Where Address = '" & sHost & "' AND timeout = 500")
    For Each oPing In cPings
        iPingResult = oPing.StatusCode
        If (iPingResult = 0) Then
            Ping = True
            Exit Function
        Else
            Ping = False
        End If
    Next
End Function

Open in new window

0
 
Bianchi928Author Commented:
spinzr0:

No, there's no blank in the input file. So I ran again the latest version you gave me and that's the result.
Very Strange !

Input File

155362S
1DCM52S
1R43T1S
23N7V1S
355362S
3LV132S
3RN1W1S
69WW12S

Output CSV file

155362S,Not Found
1DCM52S,00:24:D6:83:3C:D6
1R43T1S,00:1C:BF:8B:7F:CF
23N7V1S,Not Found
355362S,00:23:14:A6:07:B4
3LV132S,00:24:D6:09:72:E4
3RN1W1S,00:1F:3B:7B:49:51
69WW12S,Not Found
,Not Found

There's a little mistake on the last record...it shouldn't be there

Cheers
0
 
Bianchi928Author Commented:
spinzr0:

Thanks for your help.
0
 
Bianchi928Author Commented:
Well Done
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now