Retrive ServiceTag, Change IP-address

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
KBK2006
Posts: 2
Joined: 07 Jun 2012 05:26

Retrive ServiceTag, Change IP-address

#1 Post by KBK2006 » 07 Jun 2012 06:15

Hi,

I just love using Bat programs and want to share some of my work with you all.

1. ServiceTag
If you have a large number of computers that you cant access the servicetag on, this bat program will do the trick:
If you want it to export to an server just replace "C:\SERVRAR.txt" with "\\Server01\folder1\server.txt"
:: Output
:: *********************************
:: Server: SERVER1
:: IP: 192.168.1.1
:: Serial: ABCDEFGH
:: Model: Latitude D610
:: *********************************
@echo off

:: Retrive Computername
set dator=%computername%

:: Get's ip address
IPCONFIG |FIND "IPv4" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set ip=%IP:~1%

:: Get the SerialNumber/ServiceTag
for /F "skip=2 tokens=2 delims=," %%A in ('wmic bios get serialnumber /FORMAT:csv') do (set "nyckel=%%A")

:: Gets the ModellName
for /F "skip=2 tokens=2 delims=," %%A in ('wmic csproduct get name /FORMAT:csv') do (set "mnamn=%%A")

echo ********************************* >> C:\SERVRAR.txt
echo Server: %dator% >> C:\SERVRAR.txt
echo IP: %ip% >> C:\SERVRAR.txt
echo Serial: %nyckel% >> C:\SERVRAR.txt
echo Model: %mnamn% >> C:\SERVRAR.txt
echo ********************************* >> C:\SERVRAR.txt
echo. >> C:\SERVRAR.txt



2. Change IP-Address
When I was more of an server-tech guy I always had to change my ip for different reasons and got tiered of doin it manually and did a bat program with a multi choise.
@echo off
:menu
cls
echo 1 Choose IP-Address
echo 2 Choose IP-Address and Netmask
echo 3 DHCP
echo 4 Quit
echo.
set choice=
set /p choice="(1-4):"
if '%choice%'=='' goto menu
if '%choice%'=='1' goto ange
if '%choice%'=='2' goto angeb
if '%choice%'=='3' goto dhcp
if '%choice%'=='4' goto end
goto menu

:ange
echo Choose IP-Adress:
set /p IP=
netsh interface ipv4 set address name="Local Area Connection" static %IP% 255.255.255.0
pause
goto end

:angeb
echo Choose IP-Adress and netmask:
set /p IP=
netsh interface ipv4 set address name="Local Area Connection" static %IP%
pause
goto end

:dhcp
netsh interface ipv4 set address name="Local Area Connection" source=dhcp
pause
goto end

:end


Hope this help some people :P

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Retrive ServiceTag, Change IP-address

#2 Post by foxidrive » 07 Jun 2012 09:29

Welcome KBK2006

Just a quick look at the IP changer - is option 1 and 2 swapped?
Option 1 seems to set the netmask

Or is Option 2 meant to set a user defined netmask but it is missing, or you expect people to type in the IP and Netmask in the right format without error checking?

KBK2006
Posts: 2
Joined: 07 Jun 2012 05:26

Re: Retrive ServiceTag, Change IP-address

#3 Post by KBK2006 » 08 Jun 2012 05:13

foxidrive wrote:Welcome KBK2006

Just a quick look at the IP changer - is option 1 and 2 swapped?
Option 1 seems to set the netmask

Or is Option 2 meant to set a user defined netmask but it is missing, or you expect people to type in the IP and Netmask in the right format without error checking?


Option 2 is meant to be as following:
"192.168.1.100 255.255.255.0"
and it will set both :)
Well sure dont have en error checking, but it works :)

Post Reply