1

How do I display both the host name and boot time? The code I'm trying:

systeminfo | find /i "host name" && "boot time"

I know I could use

systeminfo | find /i "host name"

systeminfo | find /i "boot time"

but I really don't want to.

Basically I want the command to display the host name and boot time and ignore all else. How do I do that on one line? I know I'm missing something super simple here.

  • https://stackoverflow.com/questions/31518737/can-i-search-for-multiple-strings-in-one-find-command-in-batch-script – Iłya Bursov Feb 16 '23 at 00:38
  • 1
    find is usually not a good tool to use, findstr is better. `systeminfo | findstr /i /c:"host name" /c:"boot time"` – phuclv Feb 16 '23 at 03:33

2 Answers2

0

I have faced a similar problem before, and I may be able to help you out. If I understand your question correctly, you're looking for a way to display both the host name and boot time on one line, using a single prompt. In that case, the following command should do the trick, ignore the curly brackets of course:

{systeminfo | find /i "host name" & systeminfo | find /i "boot time"}

Using the & character will execute the two systeminfo commands sequentially and output the results on the same line.

I wish you the best of luck with your project. Let me know if I can help with anything else.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 2
    that's a terrible way to do because systeminfo is very slow and running it twice is even much less desirable – phuclv Feb 16 '23 at 02:48
  • 3
    Not only are braces not valid characters in your provided command line, I agree with the above comment. At the very least, ```systeminfo | findstr /i /c:"host name" /c:"boot time"```, would be a vast improvement. – Compo Feb 16 '23 at 02:53
  • I had never considered that. Thank you, Compo, for your insight. I am new to using CMD in a professional setting, and although my initial suggestion achieves the desired outcome, as you and phuclv pointed out, it is terribly inefficient. I appreciate your feedback and the opportunity to improve. – Denial Error Feb 16 '23 at 16:35
0

I would strongly advise against running the slowest utility on Windows, systeminfo.exe, just to get this type of information.

You could, if you wish try to use a less intensive, and quicker utility, net.exe.

You should also try to not to expect utilities to output strings in a specific language.

Example:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "CN=" & For /F "EOL= Delims=" %%G In ('(%SystemRoot%\System32\net.exe
 Stats Srv 2^>NUL ^|^| %SystemRoot%\System32\net.exe Stats Work^) ^|
 %SystemRoot%\System32\findstr.exe /ELV "."') Do If Not Defined CN (
    Set "CN=%%~nxG") Else For %%H In (%%G) Do (SetLocal EnabledelayedExpansion
    For %%I In ("!BT!") Do EndLocal & Set "BD=%%~I" & Set "BT=%%H")

If Defined CN Echo %CN% was booted on %BD% at %BT%& Pause
Compo
  • 36,585
  • 5
  • 27
  • 39