1.

Solve : Get "lastbootuptime" in YYYY/MM/DD_hh:mm format??

Answer»

This is something I should know how to do but am blanking on.

I use this command:

WMIC os getlastbootuptime

to check Windows servers after patching with BladeLogic. Is there a way to output the time in an easier-to-read format? For instance, I get

LastBootUpTime
20140211042406.359375-300

I would like to see it as 2014/02/11_04:24. I don't care about the seconds, etc.

Thanks in advance,
LaurelynThis should help you out:

Code: [Select]@echo off
setlocal

for /f "skip=1" %%i in ('wmic os get lastbootuptime') do (
SET string=%%i
goto next
)

:next
echo %string:~0,4%/%string:~4,2%/%string:~6,2%_%string:~8,2%:%string:~10,2%

Good Luck That works nicely, Sidewinder, thank you. I was thinking there was some way to do it all on a single command line but that's probably wishful Unix thinking. Seems like it would be just as easy to get it from the SystemInfo utility.
Code: [Select]H:\>systeminfo | find "System Boot Time"
System Boot Time: 2/11/2014, 7:08:39 AMFormat varies with system locale

Code: [Select]System Boot Time: 11/02/2014, 17:43:13Alternative:

for /f "tokens=1-2*" %%A in ('net statistics workstation ^| find "Statistics since"') do echo %%C

Code: [Select]11/02/2014 17:43:28Code: [Select]@echo off
for /f "tokens=1,2" %%a in ('dir c:\pagefile.sys /a-d ^|find /i ".sys" ') do echo %%a %%b

12/02/2014 21:42

but the format will conform to your regional settings.... and it assumes your pagefile is on C: (mine is on W:)
Quote from: Salmon Trout on February 12, 2014, 04:14:39 AM

... and it assumes your pagefile is on C: (mine is on W:)

You're just being difficult.

Yes indeed - I THINK your net statistics technique works well and is a single line as the op wished.Ever since I installed XP in 2001 I have had the swap file on a different partition, on a different drive. I am not sure whether to carry on this practice now I am running Windows from an SSD.
Quote from: Salmon Trout on February 12, 2014, 06:10:31 AM
Ever since I installed XP in 2001

I don't mean I am still using XP!


Squashman, thanks for that suggestion & thank you, Salmon Trout for the clarification. Looks like on 2003 servers (yeah, we still got 'em) it reports "System Up Time" instead of boot time, but that works just fine for what I'm doing too.Quote from: Salmon Trout on February 12, 2014, 06:10:31 AM
to carry on this practice now I am running Windows from an SSD.

I have an SSD and the reasoned explanations I read is that the PAGE file writes will not destroy a modern SSD and that using the SSD for the page file will speed up access by a very large factor.



Discussion

No Comment Found