Trying to get the first MAC for an IP.
The code below will print the first MAC as i want it, but also en error: unexpected command! - pointing on the last empty line of the script.

What Im donig wrong?

$IP = "192.168.10.10"

$MACz = WMIQuery("MACAddress","Win32_NetworkAdapter",$IP)

For Each $MAC in $MACz
If $MAC>0 AND NOT InStr($MAC,"50:50:54")

$PMAC = $MAC[0]

? $PMAC

EndIf

Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root, Optional $sUserID, Optional $sUserPW)
Dim $sQuery, $objEnum, $sValue, $TMP, $SystemSet, $, $objInstance, $objLocator

$sComputer = Trim(Join(Split($sComputer,'\'),''))
If NOT $sComputer OR $sComputer = @wksta
$sComputer = '.'
EndIf
If NOT $root
$root = '\root\cimv2'
EndIf
$sQuery = 'Select ' + $sWhat + ' From '+ $sFrom
If $sWhere AND $x
$sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'"
EndIf
If $sUserID AND $sUserPW AND $sComputer <> '.'
$objLocator = CreateObject('WbemScripting.SWbemLocator')
If @ERROR OR NOT $objLocator Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet = $objLocator.ConnectServer($sComputer, $root, $sUserID, $sUserPW)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet.Security_.ImpersonationLevel = 3
Else
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR OR NOT $objEnum Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
For Each $objInstance In $objEnum
$=Execute(Chr(36) + 'sValue = ' + Chr(36) + 'objInstance.' + $sWhat)
If VarType($sValue) & 8192
$tmp = $tmp +'|' + Join($sValue,'|')
Else
$tmp = $tmp +'|' + $sValue
EndIf
Next
$WMIQuery = Split(SubStr($tmp,2),'|')
Exit Val("&"+Right(DecToHex(@ERROR),4))
EndFunction
_________________________
I will always look out from behind these eyes...