Here's is part of the way there.  I have a script that takes the computer name 
and does a SQL query (via WMI) and pulls the MAC so that it can be used to send 
a WOL packet to the named machine using the WOL.dll

You will need to edit this a little bit if you want to just pull the MAC 
address - but it should be pretty clear what you need - I think the hard part 
is figuring out the SQL query and how to parse the response.

  The stuff in between the <<<< >>>> are things you need to edit.


Basically, when you get down into that "For Each Result" loop, 
Result.MACAddress, Result.IPAddress, and Result.Subnet will be filled with the 
information you are looking for.  Machinesmay have more than one active NIC so 
the script loops through them all.


Dim IPNumber, MacAddress, SubnetMask, PortNumber, CompName, strSiteServer, 
strSiteCode
                dim strQuery ' String for the Query
                dim oLocator ' SWbemLocator object
                dim gService ' SWbemServices object
                dim oQueryResult
                CompName = request.QueryString ("txtValue")
                Response.write ("Waking up " & CompName & "<br><br>")
                'You will need to edit the following line to fit your 
environment. SMSServer = Your SMS Server.  Leave the ""
                strSiteServer = "<<<<YOUR SCCM SERVERS NAME>>>>"
                'You will need to edit the following line to fit your 
environment. SMSSite Code = Your 3 Digit Site Code.  Leave the ""
                strSiteCode = "<<<<YOUR three char SITE CODE>>>>"
                set oLocator = CreateObject("WbemScripting.SWbemLocator")
                set gService = Locator.ConnectServer(strSiteServer, 
"root/sms/site_" & strSiteCode,"<<<<DOMAIN\ACCOUNT THAT CAN READ SCCM 
DATA>>>>","<<<<PASSWORD FOR THAT ACCOUNT>>>>")
                strQuery="SELECT IPAddress, MACAddress, IPSubnet " & _
          "From SMS_G_System_NETWORK_ADAPTER_CONFIGURATION INNER JOIN 
SMS_G_System_SYSTEM " & _
           "On SMS_G_System_NETWORK_ADAPTER_CONFIGURATION.ResourceID = 
SMS_G_System_SYSTEM.ResourceID " & _
          "Where SMS_G_System_NETWORK_ADAPTER_CONFIGURATION.IPEnabled=1 and 
SMS_G_System_SYSTEM.Name like " & CHR(34) & CompName & CHR(34)
                set oQueryResult = gService.ExecQuery(strQuery)
                if oQueryResult.Count = 0 then
                                response.write ("Could not locate unique IP 
address for machine<br><br>")
                else
                                response.write ("<br><br>")
                                response.write ("Found " & oQueryResult.Count & 
" possible addresses for " & CompName & ".")
                                For each Result in oQueryResult
                                                On error resume next
                                                PortNumber=<<<<YOUR PORT NUMBER 
FOR WOL>>>>
                                                
MacAddress=Replace(Result.MACAddress,":","")
                                                response.write 
("<br><br>MacAddress: " & MACAddress & vbcr)
                                                response.write ("<br>IPNumber: 
" & Result.IPAddress & vbcr)
                                                response.write 
("<br>SubnetMask: " & Result.IPSubnet & "<br>" & vbcr)
                                                If IsNull (Result.IPSubnet) or 
IsNull (Result.IPAddress) or IsNull (MACAddres) then
                                                                response.write 
("<B>SMS does not have enough information to wake up this machine.</B>")
                                                else
                                                                set WakeOnLan = 
server.createobject("DigitalWol.Wol")
                                                                
WakeOnLan.TheMacAddress(MACAddress)
                                                                
WakeOnLan.TheIpNumber(Result.IPAddress)
                                                                
WakeOnLan.TheSubnetMask(Result.IPSubnet)
                                                                
WakeOnLan.ThePortNumber(PortNumber)
                                                                
WakeOnLan.WakeMeUp

                                                end if
                                Next
    end if

From: [email protected] [mailto:[email protected]] On 
Behalf Of Stuart Watret
Sent: Friday, August 29, 2014 11:09 AM
To: [email protected]
Subject: [mssms] vb query against cm for mac


Anyone have a working vbscript example of a successful query for a mac address 
given the netbios name?



Struggling.........



Stuart Watret

Offshore - IT Ltd



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the 
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and 
may be legally privileged.  If you are not the intended recipient, you are 
hereby notified that any retention, dissemination, distribution, or copying of 
this communication is strictly prohibited.  Please reply to the sender that you 
have received the message in error, then delete it.  Thank you.
________________________________



Reply via email to