Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Collect all network PCs Serial Numbers inside text file by using batch?  (Read 8033 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Hi all,

I want to get all PCs "serial numbers" over the network by using batch as I know this command "wmic /node:%hostname% bios get serialnumber /value"  works properly separately but I want to but this command to work under for loop and for loop takes the hostnames from external text file then export the result to another text file arranged as follows " Hostname: Serial number"
Can anyone help, please?

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Collect all network PCs Serial Numbers inside text file by using batch?
« Reply #1 on: December 30, 2020, 06:03:20 AM »
Your request is like this thread : Reading text file line by line and do some operations - Windows Batch File
You just need to add some tweaks when you call the Sub :Action

Get-Serial-Numbers-Hosts.bat
Code: [Select]
@echo off
Title Collect all network PCs Serial Numbers inside text file by using batch
set "InputFile=%~dp0Hosts.txt"
set "OutPutFile=%~dp0serial_numbers.txt"
If Exist "%OutPutFile%" Del "%OutPutFile%"

If Not Exist "%InputFile%" (
color 0C & echo "%InputFile%" does not exist. Please check it first !
Timeout /T 8 /NoBreak>nul & Exit
)

set /a count=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%InputFile%"') do (
Set /a count+=1
Set "Host[!count!]=%%~a"
)

For /L %%i in (1,1,%Count%) Do (
Call :Action !Host[%%i]!
Call :Action !Host[%%i]!>>"%OutPutFile%"
)
If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Exit
::--------------------------------------------------------------------------------------
:Action
for /f "skip=1 delims=" %%a in ('wmic /node:"%1" bios get serialnumber /value') do (
for /f "tokens=2 delims==" %%b in ("%%a") do (
echo %1 : %%b
)
)
exit /b
::--------------------------------------------------------------------------------------

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Collect all network PCs Serial Numbers inside text file by using batch?
« Reply #2 on: December 31, 2020, 09:53:07 AM »
Thank you, bro, for your help and I tried to test it on my PC and it works, and also I'll test your batch in the real environment the next week Then feedback to you.
but I think it will work perfectly as usual from you as you are a prof in this field.
, so Could you help me with this case  https://www.computerhope.com/forum/index.php/topic,179675.msg1006525.html#msg1006525