2

Struggling to find the answer/code needed.

Currently using the following script. I'd like the text output file to be the Host name.

How can i do this?

@echo off
REM setlocal enabledelayedexpansion
(
systeminfo | findstr /c:"Host Name" 
systeminfo | findstr /c:"Domain" 
systeminfo | findstr /c:"OS Name" 
systeminfo | findstr /c:"OS Version" 
systeminfo | findstr /c:"System Manufacturer" 
systeminfo | findstr /c:"System Model" 
systeminfo | findstr /c:"System type" 
systeminfo | findstr /c:"Total Physical Memory" 
ipconfig | findstr IPv4

echo.

echo Hard Drive Space: 
wmic diskdrive get size

echo. 
echo.

echo Service Tag: 
wmic bios get serialnumber

echo. 
echo. 
echo CPU: 
wmic cpu get name
) > "%~dpn0.txt"
dbenham
  • 127,446
  • 28
  • 251
  • 390
Ben Donachie
  • 29
  • 1
  • 3
  • 3
    Replace `%~dpn0.txt` with `%computername%.txt`. By the way, `systeminfo` is abysmally slow compared to [`wmic`](http://stackoverflow.com/a/16044631/1683264) for this sort of thing. Do `wmic /?` and `wmic os /?` and `wmic bios /?` and `wmic computersystem /?` and so forth to get more details. – rojo May 27 '16 at 01:59
  • Whats the point of querying the domain name? Won't all of the machines have the same Domain Name? I always wonder when I see something like this. – FoxDeploy May 27 '16 at 02:28
  • @FoxDeploy Not at my workplace. The machines I work on are not on the same domain as my local domain, there are multiple domains, and they are isolated from each other. – Booga Roo May 27 '16 at 03:02
  • 1
    `systeminfo` is slooow. Instead of executing it eight times, you can speed up your program by executing it just one time, redirecting to a file and parse the file eight times. Or live with hard-to-read code with `systeminfo |findstr /c:"Host name" /c:"Domain" /c:"OS Name" ... /c:"Total Physical Memory"` – Stephan May 27 '16 at 06:14
  • @FoxDeploy about Domain Name - technically you can have workgroup pc connected into domain network accessible from domain connected pc, so even its not common situation ensuring it does not hurt :) – Drako May 27 '16 at 10:29
  • There is one problem here: all of the commands produce ASCII/ANSI output, except for `wmic`, which returns Unicode text, and all becomes mixed up; see also [this answer](https://stackoverflow.com/a/25604222/5047996) or [this one](https://stackoverflow.com/a/50985724)... – aschipfl Mar 20 '19 at 21:34

3 Answers3

0

Just some wild guesses from a newbie ...

A. I see that you are calling Windows systeminfo.exe to return your data. Could you call a third party application, like Speccy from Piriform, to return the data you want? a) www_piriform_com/speccy , b) technet_microsoft_com/en-au/library/bb491007.aspx

B. Looks like you got your code from here - https://community.spiceworks.com/how_to/63832-get-the-computer-name-ip-address-and-others-with-this-batch-file

The answer from "alinlupascu" in the above article may help you reduce waiting times for systeminfo.exe to respond. See also the answer from "joeyalbanese" - sending info to a text file.

The code from the Spiceworks article above does not use delayed expansion, perhaps it is not nescessary?

C. This doesn't seem to give any new information, but you may glean something from here - http://www.windows-commandline.com/system-information-systeminfo-command/

Glen
  • 21
  • 3
0

Just change the last line %~dpn0.txt to %ComputerName%.txt

@echo off
REM setlocal enabledelayedexpansion
(
systeminfo | findstr /c:"Host Name" 
systeminfo | findstr /c:"Domain" 
systeminfo | findstr /c:"OS Name" 
systeminfo | findstr /c:"OS Version" 
systeminfo | findstr /c:"System Manufacturer" 
systeminfo | findstr /c:"System Model" 
systeminfo | findstr /c:"System type" 
systeminfo | findstr /c:"Total Physical Memory" 
ipconfig | findstr IPv4

echo.

echo Hard Drive Space: 
wmic diskdrive get size

echo. 
echo.

echo Service Tag: 
wmic bios get serialnumber

echo. 
echo. 
echo CPU: 
wmic cpu get name
) > "%ComputerName%.txt"
Hackoo
  • 18,337
  • 3
  • 40
  • 70
0

This isn't quite as clean with spacing, but does what you want in PowerShell:

$content = systeminfo | Select-String -Pattern "Host Name","Domain","OS Name","OS Version","System Manufacturer","System Model","System type","Total Physical Memory"
$content += "`n`nHard Drive Space:"
$content += wmic diskdrive get size
$content += "`n`nService Tag:"
$content += wmic bios get serialnumber
$content += "`n`nCPU:"
$content += wmic cpu get name
$outfile = $env:computername + ".txt"
$content | Out-File $outfile -Encoding ASCII
Booga Roo
  • 1,665
  • 1
  • 21
  • 30