With the command GETMAC
in a batch file :
@echo off
Title With GETMAC Command
@For /f "tokens=1 delims=," %%a in ('getmac /NH /FO csv ^| find /I "N/A"') do (
Set "MAC=%%~a"
)
echo MAC Address = %MAC%
pause
Or with WMIC
in a batch file like this :
@echo off
Title with WMIC
@for /f "delims=" %%M in (
'Wmic Nicconfig Where IPEnabled^=true list full ^| find /I "MACAddress"'
) do (
Set "%%M"
)
echo MAC Address = %MACAddress%
pause
Or with Batch and Windows PowerShell v4.0 : You can do something like this code :
@echo off
Title Get-NetAdapter Physical
@for /f "tokens=2 delims=Up" %%a in ('Powershell -C "Get-NetAdapter -Physical" ^| findstr /I "Up"') do (
@for /f "tokens=2 delims= " %%b in ('echo "%%a"') do (
Set "PhysicalAddress=%%b"
)
)
echo MAC Address = %PhysicalAddress%
pause
Or you can also do this :
@echo off
Title GET Interface Description and MAC ADDRESS NET With Get-NetAdapter in Powershell And Batch
Set psCmdInterface="&{Get-NetAdapter -Physical | Where-Object { $_.Status -eq 'Up' } | Select-Object -Property InterfaceDescription}"
Set psCmdMAC="&{Get-NetAdapter -Physical | Where-Object { $_.Status -eq 'Up' } | Select-Object -Property MacAddress}"
REM Powershell -C %psCmdInterface%
for /f "Skip=3 tokens=1 delims=" %%a in ('Powershell -C %psCmdInterface%') do Set "Interface=%%a"
REM Powershell -C %psCmdMAC%
@for /f "Skip=3 tokens=1 delims= " %%a in ('Powershell -C %psCmdMAC%') do Set "MAC=%%a"
echo Interface = "%Interface%"
echo MAC ADDRESS = %MAC%
pause
Exit