Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

Echo out "Original Boot Time" from systeminfo command

Hey Experts!

I have a script that outputs the systeminfo from a remote computer.  This information is used for a couple of things but I'd like to improve on that script so that ONLY the "Original Boot Time" line is echo'd out, not the entire output of the command.

Suggestions on how to script this with a batch script, please.

Here is the masterpiece I wrote so far (holding back your LOL would be appreciated).  

set computeraudit=
set /p "computeraudit=Enter computer name: "

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

> ...like to improve on that script so that ONLY the "Original Boot Time" line is echo'd
Can you share your script for review?
Avatar of samiam41

ASKER

Hi NVIT.  The script (all 2 lines) in located in the bottom portion of my question above.  Thanks!
set computeraudit=
set /p "computeraudit=Enter in user's first name or string: "
for /f "tokens=2 delims=" %%a in ('systeminfo /s \\%computeraudit%' find /i "Original Boot Time"') do echo %%a

Open in new window


The last line does NOT work like I want it to so don't integrate it into your reply please.
SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Original Install Date:     02-Mar-2015, 7:49:26 PM
System Boot Time:          13-May-2015, 7:33:04 AM

Which do you want? The install date or the system boot time?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
System Boot Time

Good catch!!  Dang oversight on my part.....
@BP, that works.  Thanks!

I'm going to check the others real quick and then award points/close this out.

Thanks everyone!
Here is a update to mine, much faster than systeminfo. Just for display here at least.

@echo off

for /f "tokens=2 delims='='" %%a in ('wmic os get lastbootuptime /value') do call :format %%a
pause
exit /b

:format
set long=%1
set nyear=%long:~0,4%
set nmonth=%long:~4,2%
set nday=%long:~6,2%
set nhour=%long:~8,2%
set nminute=%long:~10,2%

echo Last boot time: %nmonth%/%nday%/%nyear% at %nhour%:%nminute%
exit /b

Open in new window

@NVIT, I copied your reply and used it as the last line in the script.  I get this error message when I use it:

ERROR:  The RPC server is unavailable



@Gabriel Clifton, it works.  Thanks.
@GC, on the new one you posted, how do I enter in a remote hostname?
Yes, i had just realized that

@echo off

for /f "tokens=2 delims='='" %%a in ('wmic /node:%computername% os get lastbootuptime /value') do call :format %%a
pause
exit /b

:format
set long=%1
set nyear=%long:~0,4%
set nmonth=%long:~4,2%
set nday=%long:~6,2%
set nhour=%long:~8,2%
set nminute=%long:~10,2%

echo Last boot time: %nmonth%/%nday%/%nyear% at %nhour%:%nminute%
exit /b

Open in new window

You get the RPC error just with mine? Did it work with Bill's?. Strange.
@GC, that is way quicker.  I made one tweak as you used the variable "computername" instead of "computeraudit".

Very fast and clean script!
@NVIT, here is the script I'm using (please verify I didn't fat-finger something)

@echo off
set computeraudit=
set /p "computeraudit=Enter computer name: "
for /f "tokens=2 delims=" %%a in ('systeminfo /s \\%computeraudit%' ^| find /i "Boot Time"') do echo %%a

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think I see one of the issues on your script for NVIT

@echo off
set computeraudit=
set /p computeraudit=Enter computer name: 
for /f "tokens=2 delims=" %%a in ('systeminfo /s \\%computeraudit% ^| find /i "Boot Time"') do echo %%a
pause

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Experts!!  I greatly appreciate your time with this and did my best to balance out the points.  I look forward to working with you all again soon!

-Aaron