This is kind of a segue from a post I did earlier at http://www.dostips.com/forum/viewtopic.php?f=3&t=6266.
This time they want me to gather information on system RAM in order to determine which systems need to be beefed up. So off to the batch scripting I went knowing the wmic command could help me.
I have the script working fine, but the output is not on one line making it difficult to import into an Excel spreadsheet for easy sorting. I am hoping some of you more experienced batch experts have dealt with getting things on one line before. So here is the code:
Code: Select all
@echo off
SETLOCAL EnableDelayedExpansion
SET output=C:\temp\DevNet_RAM.txt
echo Output file will be in %output%
pause
REM Delete any old output file if it exist.
IF EXIST "%output% DEL "%output%"
REM Ping all the IP Addresses listed in the IP file.
for /F %%G IN (C:\temp\IPList.txt) Do (
Call :ping %%G
)
GOTO :EOF
:ping
REM Ping an IP to see if it responds
ping -n 2 -w 50 %1
REM If the IP responds, errorlevel will be zero ... start collecting the RAM information
if "errorlevel%"=="0" (
echo Start ****************** >>"%output%"
REM echo the IP, System Name, System type, and RAM info to the Output file.
echo "%1" >>"%output%"
nslookup %1 | find "Name:" >>"%output%"
wmic /node:"%1" csproduct get name >>"%output%"
ping -n 2 -w 50 %1 | find "Approximate round trip " && (
wmic /node:"%1" memorychip get capacity, devicelocator >>"%output%"
)
echo End ****************** >>"%output%"
echo. >>"%output%"
)
The output is thus like this:
Code: Select all
Start ********************
"10.1.15.30"
Name: c5d5r1ff@noc.dev.net
Optiplex 9010
Capacity DeviceLocator
4294967296 DIMM1
4294967296 DIMM2
End **********************
Start ********************
"10.1.15.32"
Name: e4g2t2g1@noc.dev.net
Precision 5610
Capacity DeviceLocator
2147483648 DIMM1_CPU1
2147483648 DIMM2_CPU1
2147483648 DIMM1_CPU2
2147483648 DIMM2_CPU2
End **********************
This output is acceptable in a text file and for reading it on the screen, but as said previously not very useful for import into Excel.
If the output was something like the following:
Code: Select all
10.1.15.30 | c5d5r1f.noc.dev.net | Optiplex 9010 | 4294967296 | DIMM1 | 4294967296 | DIMM2
10.1.15.31 | e4g2t2g@noc.dev.net | Precision 5610 | 2147483648 | DIMM1_CPU1 | 2147483648 | DIMM2_CPU1 | 2147483648 | DIMM1_CPU2 | 2147483648 | DIMM2_CPU2
Then we would really be cooking with fire.
I realize the coding may not be the way experienced scriptors would do it and I am sorry for its clumsiness. Feel free to "beautify" or rewrite it as you please. Believe me, I won't complain. I'm thinking that second ping is unnecessary since the errorlevel has proven the system is alive and reachable. Also adding any comments to explain what is happening would also be greatly appreciated.
Any ideas or help in getting the output for each IP to a single line would be beyond greatly appreciated.
Kind regards to all.