batch-filecmdtruncatesystem-information

Truncate SystemInfo / Boot Time output and set as a variable?


I'm making a batch script to check on local networked PCs and would like the boot time or uptime of each PC set to a variable so I can display data however I like.

I use this command to print to screen:

SystemInfo /s PC_NAME | find "Boot Time:"

and get this result:

System Boot Time:          27/09/2019, 9:15:16 AM

But I'd like just the "27/09/2019, 9:15:16 AM" part set as a variable.

Thanks


Solution

  • Figured it out although I'm sure there would be a more efficient way:

    @ECHO Off
    SET PC_NAME=BillyPC
    SET TEMP_FILE=C:\temp\temp.txt
    SystemInfo /s %PC_NAME% | FIND "Boot Time:" > %TEMP_FILE%
    SET /p BOOT_TIME=<%TEMP_FILE%
    SET BOOT_TIME=%BOOT_TIME:~27%
    ECHO %BOOT_TIME%
    PAUSE
    

    Cheers