从命令行界面获取系统信息
Get system information from command line interface
我正在尝试创建一个脚本,当 运行 时,将输出该计算机规格的文本文件。
是否有程序提供命令行界面来生成包含 Windows OS 上的简化计算机规格的文本文件?
只是基本的消费者信息。即:RAM、CPU、HDD 等。我不需要也不想要关于计算机的每一个细节。
我知道 MSinfo32、DxDiag、Speccy 提供导出功能,但是 Speccy 不提供通过 CLI 的自动化,而其他两个只是导出所有系统信息的整体。其中大部分是个人的,对我的需要来说是不必要的。
我能想到的唯一两个解决方法是使用 Windows 等价于 grep/cat/awk 命令来筛选出必要的信息。鉴于每个系统显然具有不同的规格,这可能会证明是非常乏味的。或者,使用一个程序(如果存在的话)来指定要收集哪些规范以及要忽略哪些规范。
除了PowerShell,WMIC是一个内置的命令行工具,用于报告WMI数据,包括各种系统信息,并以各种格式输出。它没有固定的系统硬件报告,但您可以使用它来准确获取所需的设置。
例如,要列出计算机上的驱动器,我可以发出以下命令:
C:\>wmic diskdrive get Manufacturer,Partitions,Size /value
Manufacturer=(Standard disk drives)
Partitions=2
Size=320070320640
...
或者,如果您想要有关特定项目的大量信息,您可以使用:
wmic cpu list /format:list
AddressWidth=64
Architecture=9
Availability=3
Caption=Intel64 Family 6 Model 26 Stepping 5
ConfigManagerErrorCode=
ConfigManagerUserConfig=
CpuStatus=1
CreationClassName=Win32_Processor
CurrentClockSpeed=2794
CurrentVoltage=
DataWidth=64
Description=Intel64 Family 6 Model 26 Stepping 5
DeviceID=CPU0
...
LoadPercentage=24
Manufacturer=GenuineIntel
MaxClockSpeed=2794
Name=Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
此网站展示了一些关于 WMIC or PowerShell
的优秀示例
Microsoft 在线提供了 full documentation,但并不能真正让您了解如何使用它。
在 powershell 中:
$System = Get-CimInstance CIM_ComputerSystem
$BIOS = Get-CimInstance CIM_BIOSElement
$OS = Get-CimInstance CIM_OperatingSystem
$CPU = Get-CimInstance CIM_Processor
$HDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$EXTXT = "$env:USERPROFILE\Desktop\welp.txt"
Clear-Host
"Manufacturer: " + $System.Manufacturer >> $EXTXT
"Model: " + $System.Model >> $EXTXT
"CPU: " + $CPU.Name >> $EXTXT
"RAM: " + "{0:N2}" -f ($System.TotalPhysicalMemory/1GB) + "GB" >> $EXTXT
"HDD Capacity: " + "{0:N2}" -f ($HDD.Size/1GB) + "GB" >> $EXTXT
"Operating System: " + $OS.caption >> $EXTXT
对我问题的回复让我获得了更好的搜索结果。大部分源代码来自这里:http://community.spiceworks.com/scripts/show_download/1831
之后我能够拼凑附加和东西。另存为 .ps1 格式就可以了。
或者,如果您愿意,这里是用 Python 编写的相同的、相关的脚本。使用本机 Windows 和 PowerShell 命令。
import os
import wmi
import math
c = wmi.WMI()
SYSINFO = c.Win32_ComputerSystem()[0]
OSINFO = c.Win32_OperatingSystem()[0]
CPUINFO = c.Win32_Processor()[0]
HDDINFO = c.Win32_LogicalDisk()[0]
RAMINFO = c.Win32_PhysicalMemory()[0]
MANUFACTURER = SYSINFO.Manufacturer
MODEL = SYSINFO.Model
RAMTOTAL = int(SYSINFO.TotalPhysicalMemory)
HDDTOTAL = int(HDDINFO.size)
RAMSIZE = round(RAMTOTAL)
HDDSIZE = round(HDDTOTAL)
os.system('cls')
print "Model: " + MANUFACTURER + " " + MODEL
print "\r"
print "HDD: " + str(HDDTOTAL) + "GB"
print "RAM: " + str(RAMTOTAL) + "GB"
print "CPU: " + CPUINFO.name
print "OS: " + OSINFO.caption
我正在尝试创建一个脚本,当 运行 时,将输出该计算机规格的文本文件。
是否有程序提供命令行界面来生成包含 Windows OS 上的简化计算机规格的文本文件?
只是基本的消费者信息。即:RAM、CPU、HDD 等。我不需要也不想要关于计算机的每一个细节。
我知道 MSinfo32、DxDiag、Speccy 提供导出功能,但是 Speccy 不提供通过 CLI 的自动化,而其他两个只是导出所有系统信息的整体。其中大部分是个人的,对我的需要来说是不必要的。
我能想到的唯一两个解决方法是使用 Windows 等价于 grep/cat/awk 命令来筛选出必要的信息。鉴于每个系统显然具有不同的规格,这可能会证明是非常乏味的。或者,使用一个程序(如果存在的话)来指定要收集哪些规范以及要忽略哪些规范。
除了PowerShell,WMIC是一个内置的命令行工具,用于报告WMI数据,包括各种系统信息,并以各种格式输出。它没有固定的系统硬件报告,但您可以使用它来准确获取所需的设置。
例如,要列出计算机上的驱动器,我可以发出以下命令:
C:\>wmic diskdrive get Manufacturer,Partitions,Size /value
Manufacturer=(Standard disk drives)
Partitions=2
Size=320070320640
...
或者,如果您想要有关特定项目的大量信息,您可以使用:
wmic cpu list /format:list
AddressWidth=64
Architecture=9
Availability=3
Caption=Intel64 Family 6 Model 26 Stepping 5
ConfigManagerErrorCode=
ConfigManagerUserConfig=
CpuStatus=1
CreationClassName=Win32_Processor
CurrentClockSpeed=2794
CurrentVoltage=
DataWidth=64
Description=Intel64 Family 6 Model 26 Stepping 5
DeviceID=CPU0
...
LoadPercentage=24
Manufacturer=GenuineIntel
MaxClockSpeed=2794
Name=Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
此网站展示了一些关于 WMIC or PowerShell
的优秀示例Microsoft 在线提供了 full documentation,但并不能真正让您了解如何使用它。
在 powershell 中:
$System = Get-CimInstance CIM_ComputerSystem
$BIOS = Get-CimInstance CIM_BIOSElement
$OS = Get-CimInstance CIM_OperatingSystem
$CPU = Get-CimInstance CIM_Processor
$HDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$EXTXT = "$env:USERPROFILE\Desktop\welp.txt"
Clear-Host
"Manufacturer: " + $System.Manufacturer >> $EXTXT
"Model: " + $System.Model >> $EXTXT
"CPU: " + $CPU.Name >> $EXTXT
"RAM: " + "{0:N2}" -f ($System.TotalPhysicalMemory/1GB) + "GB" >> $EXTXT
"HDD Capacity: " + "{0:N2}" -f ($HDD.Size/1GB) + "GB" >> $EXTXT
"Operating System: " + $OS.caption >> $EXTXT
对我问题的回复让我获得了更好的搜索结果。大部分源代码来自这里:http://community.spiceworks.com/scripts/show_download/1831
之后我能够拼凑附加和东西。另存为 .ps1 格式就可以了。
或者,如果您愿意,这里是用 Python 编写的相同的、相关的脚本。使用本机 Windows 和 PowerShell 命令。
import os
import wmi
import math
c = wmi.WMI()
SYSINFO = c.Win32_ComputerSystem()[0]
OSINFO = c.Win32_OperatingSystem()[0]
CPUINFO = c.Win32_Processor()[0]
HDDINFO = c.Win32_LogicalDisk()[0]
RAMINFO = c.Win32_PhysicalMemory()[0]
MANUFACTURER = SYSINFO.Manufacturer
MODEL = SYSINFO.Model
RAMTOTAL = int(SYSINFO.TotalPhysicalMemory)
HDDTOTAL = int(HDDINFO.size)
RAMSIZE = round(RAMTOTAL)
HDDSIZE = round(HDDTOTAL)
os.system('cls')
print "Model: " + MANUFACTURER + " " + MODEL
print "\r"
print "HDD: " + str(HDDTOTAL) + "GB"
print "RAM: " + str(RAMTOTAL) + "GB"
print "CPU: " + CPUINFO.name
print "OS: " + OSINFO.caption