2016-05-27 36 views
2

努力尋找所需的答案/代碼。基於主機名的批量文件輸出

當前使用以下腳本。我希望文本輸出文件是主機名。

我該怎麼做?

@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" 
+3

用'%computername%.txt'替換'%〜dpn0.txt'。順便說一句,'systeminfo'比這個['wmic'](http://stackoverflow.com/a/16044631/1683264)要糟糕得多。做'wmic /?'和'wmic os /?'和'wmic bios /?'和'wmic computersystem /?'等等以獲得更多細節。 – rojo

+0

查詢域名有什麼意義?是不是所有的機器都有相同的域名?當我看到這樣的事情時,我總是懷疑。 – FoxDeploy

+0

@FoxDeploy不在我的工作場所。我工作的機器與本地域不在同一個域中,有多個域,並且它們彼此隔離。 –

回答

0

從一個新手只是一些亂撞......

答:我看到你調用Windows systeminfo.exe來回報您的數據。 你能否像Piriform的Speccy那樣調用第三方應用程序來返回你想要的數據? 一)www_piriform_com/speccy, B)technet_microsoft_com/EN-AU /庫/ bb491007.aspx

B看起來你在這裏有你的代碼 - https://community.spiceworks.com/how_to/63832-get-the-computer-name-ip-address-and-others-with-this-batch-file

在從 「alinlupascu」 答案上面的文章可能會幫助您減少systeminfo.exe響應的等待時間。另請參閱「joeyalbanese」的答案 - 將信息發送到文本文件。

以上Spiceworks文章的代碼不使用延遲擴展,也許它不是必需的?

C.這似乎並沒有給予任何新的信息,但你可以蒐集一些從這裏開始 - http://www.windows-commandline.com/system-information-systeminfo-command/

0

只需更改最後一行%~dpn0.txt%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" 
0

這不是相當乾淨的間距,但在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