Here is the batch script that is allowing me to export data from the batch file to CSV:
@echo off
Set Configout=\YourNetworkShare\File.txt
SET ConfigOutCred=/USER:USERNAME@DOMAIN /Pass:PASSWORD
color 0c
echo.
echo Exporting System Info...
Date /T >>%Configout% %ConfigOutCred%
for /F "tokens=1 delims= " %%G in ('hostname') do (
echo "%%G" >> %Configout%
)
(Systeminfo | findstr /C:BIOS)>>%Configout%
(systeminfo | findstr /B /C:"OS Name" /C:"OS Version")>>%Configout%
setlocal enableextensions enabledelayedexpansion
for /F "skip=3 tokens=1,2" %%L in ('getmac') do (
set __mac=%%L
set __transport=%%M
if /i not "!__transport!"=="N/A" (
if /i not "!__transport!"=="Media disconnected" (
if /i not "!__transport!"=="Media" (
echo "%%L" >> %Configout%
)
)
)
)
endlocal
for /F "tokens=2 delims=:" %%F in ('ipconfig^|find "IPv4 Address"') do (
set __IP=%%F
echo "%%F" >> %Configout%
)
for /F "tokens=1,2,3 delims= " %%H in ('wmic csproduct get name') do (
echo "%%H" >> %Configout%
)
for /F "tokens=1,2,3 delims= " %%I in ('wmic csproduct get vendor') do (
echo "%%I" >> %Configout%
)
for /F "tokens=1,2,3 delims= " %%J in ('wmic csproduct get version') do (
echo "%%J" >> %Configout%
)
for /F "tokens=1,2,3 delims= " %%K in ('wmic bios get serialnumber') do (
echo "%%K" >> %Configout%
)
wmic os get osarchitecture>>%Configout%
echo.
echo System Info has been exported!
: notepad.exe \YourNetworkShare\File.txt
pause
exit
Using the above batch file will output the following info:
Current Date
PC Hostname
BIOS Version and Date
OS Name
OS Version and SP
MAC Addresses of active adapters
IP Addresses of active adapters
PC Model
PC Brand
PC Version
PC Serial Number
OS Architecture (32-Bit or 64-Bit)
After it grabs this data, it will create a text file in whichever network folder specified with fully qualified domain credentials. When it is run on subsequent machines, it will append the text file and add it to the bottom (With the OS Arch. and the Date making an easy separator to eyeball).
Note: I left the 'pause' and 'notepad' strings in for testing if anyone likes.
You rock Spork! Everything is doing what I need.
FOR /F "tokens=1 delims= " %%G IN ('%_hostname_cmd% ^find "FCRS"') DO echo Result is [%%G] in (C:\Users\Cesadmin\Desktop) pause
. The script runs and does not error, however, it does not create a text file. TheFCRS
that it's looking for is the prefix to every PC on my site. Where did I go wrong? This is my first time attempting this, so please bear with my ignorance 🙂 — Megallica>
operator to create/overwrite a file, and>>
to append. A simple example using justhostname
(you can modify the command to your liking):for /F "tokens=1 delims= " %%G in ('hostname') do ( echo Result is [%%G] > sample.txt )
This will direct the output of the "echo" command to sample.txt. — sporkfor /F "tokens=* delims= " %%G in ('wmic csproduct get name, vendor, version') do (echo [%%G] > SystemInfo.txt
Can I pull the data from the same command or do I have to separate out the name/vendor/version? Lastly, if I made all of the commands in succession EX:for /F "tokens=1 delims= " %%G in ('hostname') do (echo [%%G] > SystemInfo.txt
and thenfor /F "tokens=* delims= " %%G in ('wmic csproduct get name, vendor, version') do (echo [%%G] > SystemInfo.txt
Will this output to the same file or overwrite as each command runs? Thanks again. Your assistance is really appreciated! — Megallicafor /F "tokens=1 delims= " %%G in ('hostname') do ( echo [%%G] > SystemInfo.txt )
andfor /F "tokens=* delims= " %%G in ('wmic csproduct get name, vendor, version') do ( echo [%%G] >> SystemInfo.txt )
Also, if you're pulling multiple tokens from a line, they'll be dumped into successive variables, starting with the one in the FOR loop, i.e. the first token will be in%%G
, the second one in%%H
, and so forth. — sporkPhysical Address Transport Name =================== ========================================================== 3C-97-0E-A9-7B-79 Media disconnected 6C-88-14-BB-84-1C \Device\Tcpip_{A1C49BAE-3AA2-4016-83FC-451E9B5F5AB3} F8-2F-A8-E3-49-6B Media disconnected 00-60-73-53-B5-74 \Device\Tcpip_{44CF952C-B243-424E-92B3-3461D0A6A4E9}
I only want the Header and 2nd and 4th MAC addresses (Wired and Wireless NIC) Would it also be possible to export only the IP address from IP Config the same way? Thanks — Megallica@echo off setlocal enableextensions enabledelayedexpansion echo physicaladdress,transportname for /F "skip=3 tokens=1,2" %%G in ('getmac') do ( set __mac=%%G set __transport=%%H if /i not "!__transport!"=="N/A" ( if /i not "!__transport!"=="Media disconnected" ( echo !__mac!,!__transport! ) ) ) endlocal
I didn't bother parsing the headers since you can just echo those manually. The script above produces this for me:physicaladdress,transportname 74-E3-D1-CA-4D-F5,\Device\Tcpip_{F1D51C7D-6552-4640-8D2C-55A3F8DD196B} 10-72-5D-4D-5D-82,\Device\Tcpip_{E4DF4431-3F5B-4E57-8E7A-83B1EB34BF71}
Extracting IP's from ipconfig would follow roughly the same logic -- you'll just have more data to deal with and conditions to check for. — spork