Simple Batch Script to Display System Information in proper html format



This is a simple batch script to display the system information and status of the system in html format in a proper design. The script is written in the Windows 7 batch programming and in some places Power shell is used as to calculate some big digits I hope this will work for some organizations where they wanted to send the emails of there servers or systems information


System Health











Code :
@echo off
echo ^<table width="100%%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:#818181 solid 0px; font-family:Arial, Helvetica, sans-serif; font-size:16px;"^> > hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td style="background: -webkit-gradient(linear, left top, left bottom, from(#01619b), to(#0879bd)); background: -moz-linear-gradient(top, #01619b, #0879bd); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff5400, endColorstr=#e84e02);" style="border:#818181 solid 1px;"^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td style="font-size:45px; padding-left:8px; color:#fff; font-weight:bold;" align="center"^>System Information and Status Checks Report^</td^> >> hname.html
echo ^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^</tbody^>^</table^>^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^> >> hname.html
echo ^<td align="left" valign="top" style="border:#818181 solid 1px;"^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tr^> >> hname.html >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td height="35" align="center" bgcolor="#333" style="color:#fff; border-bottom:#818181 solid 1px;"^> %date%  at %time:~0,5% ^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<td height="30" bgcolor="#bddbee" style="border-bottom:#757575 solid 1px; padding-left:5px; font-weight:bold;"^>Host Information^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^> >> hname.html
echo ^<td^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td width="9%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Host Name^</td^> >> hname.html
echo ^<td width="8%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>IP Address^</td^> >> hname.html
echo ^<td width="17%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>OS Version^</td^> >> hname.html
echo ^<td width="22%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Kernel Version^</td^> >> hname.html
echo ^<td width="23%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>CPU Model Version^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>CPU Make^</td^> >> hname.html
echo ^<td width="11%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 0px; border-bottom:#818181 solid 1px; font-size:14px;"^>Number of Cores^</td^> >> hname.html
echo ^</tr^> >> hname.html
for /F "skip=2 tokens=1-7 delims=," %%A in ('wmic path Win32_Processor get name^,Description^,Manufacturer^,NumberOfCores^ /Format:"%WINDIR%\System32\wbem\en-us\csv"') do (
set hname=%%A
set desname=%%B
set proname=%%C
set stat=%%D
set core=%%E
)
for /F "skip=2 tokens=1-7 delims=," %%A in ('Wmic path Win32_OperatingSystem get Caption^,LastBootUptime^,CSDversion^ /Format:"%WINDIR%\System32\wbem\en-us\csv"') do (
set sname=%%A
set cname=%%B
set lbu=%%C
set csd=%%D
)
for /F "skip=2 tokens=1-7 delims=," %%A in ('Wmic path Win32_NetworkAdapterConfiguration where "Description='Intel(R) Ethernet Connection I217-LM'" get IPAddress^,DNSDomain^,DNSServerSearchOrder^,DefaultIPGateway^,MACAddress^/Format:"%WINDIR%\System32\wbem\en-us\csv"') do (
set IP=%%D
set DNDD=%%C
set DG=%%B
set MADD=%%F
set ns=%%D
)
set w=width="33%" height="25"
set a=align="center"
set s=style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:11px;"
set h=height="30"
set fs=style="font-size: 10px;"
set fname=hname.html
echo ^<tr %fs% ^> >> %fname%
echo ^<td %w% %a% %s% ^> %sname% ^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %IP:~1,13%^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %cname% ^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %lbu% ^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %stat% ^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %proname% ^</td^> >> %fname%
echo ^<td %w% %a% %s% ^> %core% ^</td^> >> %fname%
echo ^</tr^> >> %fname%
echo ^</tr^> >> hname.html
echo ^</tbody^>^</table^>^</td^> >> hname.html
echo ^</tr^>  >> hname.html
echo ^</tbody^>^</table^>^</td^>  >> hname.html
echo ^</tr^>  >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td height="8"^>^</td^>  >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^> >> hname.html
echo ^<td style="border:#818181 solid 1px;"^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td height="30" bgcolor="#bddbee" style="border-bottom:#757575 solid 1px; padding-left:5px; font-weight:bold;"^>Boot Information^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td width="35%%" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Host Name^</td^> >> hname.html
echo ^<td width="35%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Uptime^</td^> >> hname.html
echo ^<td width="35%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Last Reboot^</td^> >> hname.html
echo ^</tr^> >> hname.html
set bootname=hname.html
for /f "delims=" %%a in ('wmic OS Get LastBootUpTime ^| find "."') do set up=%%a
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set beg=%up:~0,4%-%up:~4,2%-%up:~6,2%T%up:~8,2%-%up:~10,2%-%up:~12,2%-%up:~15,3%
set end=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%T%dt:~8,2%-%dt:~10,2%-%dt:~12,2%-%dt:~15,3%
call :TimeDifference uptime %end% %beg%
for /f "Tokens=2 Delims==" %%i in ('wmic OS Get LastBootUpTime /format:list') Do Set LastBootUpTime=%%i
Set LBT-Year=%LastBootUpTime:~0,4%||:   yyy
Set LBT-Month=%LastBootUpTime:~4,2%||:   mm
Set LBTDay=%LastBootUpTime:~6,2%||:   dd
Set LBT-Hour=%LastBootUpTime:~8,2%||:    hh
Set LBT-Minte=%LastBootUpTime:~10,2%||: mm
Set LBT-Second=%LastBootUpTime:~12,2%||: ss
set LastBootDate= %LBTDay% - %LBT-Month% - %LBT-Year% at %LBT-Hour%^:%LBT-Minte%^:%LBT-Second%
echo ^<tr %fs% ^> >> %bootname%
echo ^<td %w% %a% %s% ^> %sname% ^</td^> >> %bootname%
echo ^<td %w% %a% %s% ^> %uptime% ^</td^> >> %bootname%
echo ^<td %w% %a% %s% ^> %LastBootDate%  ^</td^> >> %bootname%

:Disk Information
echo ^</tr^> >> hname.html
echo ^</tbody^>^</table^>^</td^> >> hname.html
echo ^</tr^>  >> hname.html
echo ^</tbody^>^</table^>^</td^>  >> hname.html
echo ^</tr^>  >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td height="8"^>^</td^>  >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^> >> hname.html
echo ^<td style="border:#818181 solid 1px;"^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td height="30" bgcolor="#bddbee" style="border-bottom:#757575 solid 1px; padding-left:5px; font-weight:bold;"^>Disk Drive Information^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td width="18%%" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Host Name^</td^> >> hname.html
echo ^<td width="12%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Device Name^</td^> >> hname.html
echo ^<td width="12%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>File System^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Mount Point^</td^> >> hname.html
echo ^<td width="15%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Total Size ^</td^> >> hname.html
echo ^<td width="15%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Available Space^</td^> >> hname.html
echo ^<td width="18%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 0px; border-bottom:#818181 solid 1px; font-size:14px;"^>Used Space^</td^>  >> hname.html
echo ^</tr^> >> hname.html
set minfo=hname.html
set backc=style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:11px;  background:green; color:#fff; "
set backr=style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:11px;  background:red; color:#fff; "
set row=align="center" rowspan="3"
echo ^<tr %fs% ^> >> %minfo%
echo ^<td %row% %w% %a% %s% ^> %sname% ^</td^> >> %minfo%
wmic logicaldisk where "DeviceID='C:'" get Caption,Description,Filesystem,Size,FreeSpace /format:"%WINDIR%\System32\wbem\en-us\csv" > logical.txt
for /F "skip=2 tokens=1-7 delims=," %%A in ('type logical.txt') do (
set ts=%%F
set fsp=%%E
set cap=%%B
set Diskdesc=%%C
set filesys=%%D
)
for /F %%A in ('powershell^(%ts%/1024/1024/1024^)') do set tspace=%%A
for /F %%A in ('powershell^(%fsp%/1024/1024/1024^)') do set fspace=%%A
for /F %%A in ('powershell^(%ts%/100^)') do set tper=%%A
for /F %%A in ('powershell^(%ts%-%fsp%^)') do set uspace=%%A
for /F %%A in ('powershell^(%uspace%/%tper%^)') do set uper=%%A
echo ^<td %h% %a% %s% ^> %Diskdesc% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %filesys% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %cap% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %tspace:~0,5% GB  ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %fspace:~0,5% GB  ^</td^> >> %minfo%
echo ^<td %h% %a% %backc% ^> %uper:~0,2%%%^</td^> >> %minfo%

:second drive
echo ^<tr %fs% ^> >> %minfo%
wmic logicaldisk where "DeviceID='D:'" get Caption,Description,Filesystem,Size,FreeSpace /format:"%WINDIR%\System32\wbem\en-us\csv" > logical.txt
for /F "skip=2 tokens=1-7 delims=," %%A in ('type logical.txt') do (
set ts=%%F
set fsp=%%E
set cap=%%B
set Diskdesc=%%C
set filesys=%%D

)
for /F %%A in ('powershell^(%ts%/1024/1024/1024^)') do set tspace=%%A
for /F %%A in ('powershell^(%fsp%/1024/1024/1024^)') do set fspace=%%A

for /F %%A in ('powershell^(%ts%/100^)') do set tper=%%A
for /F %%A in ('powershell^(%ts%-%fsp%^)') do set uspace=%%A
for /F %%A in ('powershell^(%uspace%/%tper%^)') do set uper=%%A
echo ^<td %h% %a% %s% ^> %Diskdesc% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %filesys% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %cap% ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %tspace:~0,5% GB  ^</td^> >> %minfo%
echo ^<td %h% %a% %s% ^> %fspace:~0,5% GB  ^</td^> >> %minfo%
echo ^<td %h% %a% %backc% ^> %uper:~0,2%%%^</td^> >> %minfo%

echo ^</tr^> >> hname.html
echo ^</tbody^>^</table^>^</td^> >> hname.html
echo ^</tr^>  >> hname.html
echo ^</tbody^>^</table^>^</td^>  >> hname.html
echo ^</tr^>  >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td height="8"^>^</td^>  >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^> >> hname.html
echo ^<td style="border:#818181 solid 1px;"^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td height="30" bgcolor="#bddbee" style="border-bottom:#757575 solid 1px; padding-left:5px; font-weight:bold;"^>Network Information^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^<tr^>  >> hname.html
echo ^<td^>^<table width="100%%" border="0" cellspacing="0" cellpadding="0"^> >> hname.html
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td width="10%%" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Host Name^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>IP Addres^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Sub Netmask^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>DNS Server^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Mac Address^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Gateway^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Packets Received^</td^> >> hname.html
echo ^<td width="10%%" height="30" align="center" bgcolor="#e1eff8" style="border-right:#818181 solid 1px; border-bottom:#818181 solid 1px; font-size:14px;"^>Packets Send^</td^> >> hname.html
echo ^</tr^> >> hname.html
for /F "skip=2 tokens=1-7 delims=," %%A in ('Wmic path Win32_NetworkAdapterConfiguration where "Description='Intel(R) Ethernet Connection I217-LM'" get IPAddress^,DNSDomain^,DNSServerSearchOrder^,DefaultIPGateway^,MACAddress^,IPSubnet^/Format:"%WINDIR%\System32\wbem\en-us\csv"') do (
set DNDD=%%C
set DG=%%B
set MADD=%%E
set ns=%%D
set IPsub=%%F
)
set ninfo=hname.html
echo ^<tr %fs% ^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %sname% ^</td^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %IP:~1,13% ^</td^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %MADD% ^</td^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %DNDD% ^<br/^> ^</td^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %IPsub% ^</td^> >> %ninfo%
echo ^<td %w% %a% %s% ^> %DG% ^</td^> >> %ninfo%
ipconfig | findstr "Gateway" > bytes.txt
for /F "tokens=1-5 delims=:" %%A in ('type bytes.txt') do (
)
net statistics workstation | findstr "Bytes" | findstr "received" > bytes.txt
for /F "tokens=1-6 delims= " %%A in ('type bytes.txt') do (
set rece=%%C
)
powershell %rece%/1024/1024/1024 > gb.txt
for /F "tokens=1-6 delims=" %%A in ('type gb.txt') do (
set rr=%%A
)
echo ^<td %w% %a% %s% ^> %rr:~0,4% GB ^</td^> >> %ninfo%
net statistics workstation | findstr "Bytes" | findstr "transmitted" > bytes.txt
for /F "tokens=1-6 delims= " %%A in ('type bytes.txt') do (
set trans=%%C
)
powershell %trans%/1024/1024/1024 > gb.txt
for /F "tokens=1-6 delims=" %%A in ('type gb.txt') do (
set tt=%%A
)
echo ^<td %w% %a% %s% ^> %tt:~0,4% GB ^</td^> >> %ninfo%
echo ^</tr^> >> %ninfo%
echo ^</tbody^>^</table^>^</td^> >> %ninfo%
echo ^</tr^> >> %ninfo%
echo ^</tbody^>^</table^>^</td^>  >> %ninfo%
echo ^</tr^>^</tbody^>^</table^>  >> %ninfo%
echo ^<tbody^>^<tr^> >> hname.html
echo ^<td^>Report generated by Chandra Prakash Kadarla^</td^> >> hname.html
echo ^</td^> >> hname.html
echo ^</tr^> >> hname.html
echo ^</tbody^>^</table^>^</td^> >> hname.html
call hname.html

:TimeDifference
SetLocal EnableExtensions EnableDelayedExpansion
For /F "tokens=1-14 delims=T/:-., " %%a in ("%~2 %~3") Do (
  Set "h2=0%%d" & Set "h3=0%%k" & Set "n2=%%g00" & Set "n3=%%n00"
  Set /A "y2=%%a, m2=1%%b-100, d2=1%%c-100, h2=1!h2:~-2!-100, i2=1%%e-100, s2=1%%f-100, n2=1!n2:~0,3!-1000"
  Set /A "y3=%%h, m3=1%%i-100, d3=1%%j-100, h3=1!h3:~-2!-100, i3=1%%l-100, s3=1%%m-100, n3=1!n3:~0,3!-1000"
)
Set /A "t2=((h2*60+i2)*60+s2)*1000+n2, t3=((h3*60+i3)*60+s3)*1000+n3"
Set /A "a=(14-m2)/12, b=y2-a, j2=(153*(12*a+m2-3)+2)/5+d2+365*b+b/4-b/100+b/400"
Set /A "a=(14-m3)/12, b=y3-a, j3=(153*(12*a+m3-3)+2)/5+d3+365*b+b/4-b/100+b/400"
Set /A "d=j3-j2, t=t3-t2"
If %d% LEQ 0 (If %d% LSS 0 (Set /A "d=j2-j3, t=t2-t3") Else If %t% LSS 0 (Set /A "t=t2-t3"))
If %t% LSS 0 (Set /A "t+=(1000*60*60*24), d-=1")
Set /A "n=t %% 1000, t/=1000, s=t %% 60, t/=60, m=t %% 60, t/=60"
EndLocal & Set "%~1= %d% Days  %t% Hours"




Download

Please give comments and suggestions are always welcome


Keywords: System information, Batch Script, System Health status 






Comments

Popular posts from this blog

Observium: Configuring Microsoft Windows 2008 Server SNMP Agent

AWS: Introduction to AWS (Amazon Web Services)

System/Server Health Status using PowerShell