How to get pc mac address and restart PC if mac is not on the list.txt?, i only have this getting mac command,
for /f "tokens=3 delims=," %%a in ('"getmac /v /fo csv | findstr Ethernet"') do set MAC=%%a
echo MAC address of this computer is %MAC%
How to get pc mac address and restart PC if mac is not on the list.txt?, i only have this getting mac command,
for /f "tokens=3 delims=," %%a in ('"getmac /v /fo csv | findstr Ethernet"') do set MAC=%%a
echo MAC address of this computer is %MAC%
getmac and pipe the result through findstr to filter on the required network adaptor.
ThisPCMACtype command to get the content of the list.txt file piped through findstr to filter on ThisPCMAC.
FoundMAC.FoundMAC is defined you goto :norestartFoundMAC is not defined you goto :restart:restart, you call shutdown /r with the required additional paramsshutdown /a in the allotted time (10 minutes here, see /t 600).shutdown /?The 2 files should be in the same directory.
Example content of list.txt:
FF-AA-BB-CC-DD-FA FF-AA-BB-CC-DD-FB FF-AA-BB-CC-DD-FC
Content of RestartIfThisPCMACnotInList.bat:
@echo off set ScriptPath=%~dp0 set ThisPCMAC= set FoundMAC= echo. echo ScriptPath = %ScriptPath% for /f "tokens=3 delims=," %%a in ('"getmac /v /fo csv | findstr Ethernet"') do set ThisPCMAC=%%a echo. echo MAC address of this computer is %ThisPCMAC% for /F "usebackq delims==" %%b in (`"type %ScriptPath%list.txt | findstr %ThisPCMAC%"`) do set FoundMAC=%%b if DEFINED FoundMAC ( goto :norestart ) else ( goto :restart ) :norestart echo. echo Found %FoundMAC% in %ScriptPath%list.txt: Nothing to do. goto :end :restart echo. echo %ThisPCMAC% not found in %ScriptPath%list.txt: Restarting... echo. echo shutdown /r /f /t 600 /d p:00:00 shutdown /r /f /t 600 /d p:00:00 echo. echo Cancel restart with the following command: echo shutdown /a goto :end :end echo. echo %~fp0 ended. pause
Example output for :norestart:
C:\test\>RestartIfThisPCMACnotInList.bat ScriptPath = C:\test\ MAC address of this computer is "FF-AA-BB-CC-DD-FA" Found FF-AA-BB-CC-DD-FA in C:\test\list.txt: Nothing to do. C:\test\RestartIfThisPCMACnotInList.bat ended. Press any key to continue . . .
Example output for :restart:
C:\test\>RestartIfThisPCMACnotInList.bat ScriptPath = C:\test\ MAC address of this computer is "FF-AA-BB-CC-DD-FD" "FF-AA-BB-CC-DD-FD" not found in C:\test\list.txt: Restarting... shutdown /r /f /t 600 /d p:00:00 Cancel restart with the following command: shutdown /a C:\test\RestartIfThisPCMACnotInList.bat ended. Press any key to continue . . .