返回列表 发帖

[系统相关] 获取 硬件信息,尽量用 powershell 吧

powershell 比批处理,易读性好多了
function Get_CurrentDateTime() {
[void]$info.add( "信息提取时间:" + (Get-Date).ToString('yyyy-MM-dd HH:mm:ss') )
[void]$info.add( "" )
}
# 获取操作系统信息
function Get_Info_system() {
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem
[void]$info.add( "OS:" )
[void]$info.add( "    Name      :$( $osInfo.Caption ) 【 $( $osInfo.OSArchitecture ) 】" )
[void]$info.add( "    Version   :$( $osInfo.Version )" )
[void]$info.add( "    安装日期  :$( $osInfo.InstallDate.ToString('yyyy-MM-dd') )" )
[void]$info.add( "    BIOS Mode : $env:firmware_type" )
[void]$info.add( "" )
}
# 获取产品信息
function Get_Info_Product() {
$productInfo = Get-CimInstance -ClassName Win32_ComputerSystemProduct
[void]$info.add( "产品:" )
[void]$info.add( "    供应商:" + $productInfo.Vendor )
[void]$info.add( "    系列  :" + $productInfo.Name )
[void]$info.add( "    型号  :" + $productInfo.Version )
[void]$info.add( "    序列号:" + $productInfo.IdentifyingNumber )
[void]$info.add( "" )
}
# 获取主板信息
function Get_Info_BaseBoard() {
$baseboardInfo = Get-CimInstance -ClassName Win32_BaseBoard
[void]$info.add( "主板:" )
[void]$info.add( "    制造商:" + $baseboardInfo.Manufacturer )
[void]$info.add( "    产品  :" + $baseboardInfo.Product )
[void]$info.add( "    序列号:" + $baseboardInfo.SerialNumber )
[void]$info.add( "" )
}
# 获取处理器信息
function Get_Info_Processor() {
$processorInfo = Get-CimInstance -ClassName Win32_Processor
[void]$info.add( "CPU :【 $( ($processorInfo | Measure-Object).Count ) 】" )
foreach ($processor in $processorInfo) {
[void]$info.add( "    名称: $( $processor.Name ) 【 $( $processor.NumberOfCores ) 核 $( $processor.NumberOfLogicalProcessors ) 线程 】" )
[void]$info.add( "    主频:" + $processor.MaxClockSpeed )
}
[void]$info.add( "" )
}
# 获取内存信息
function Get_Info_Memory() {
$memoryInfo = Get-CimInstance -ClassName Win32_PhysicalMemory
[void]$info.add( "内存:【 $( ($memoryInfo | Measure-Object).Count ) 】" )
[void]$info.add( "    总容量: {0} GB" -f $( ( $memoryInfo | Measure-Object -Property Capacity -Sum ).Sum / 1GB ) )
foreach ($memory in $memoryInfo) {
#$( $memory.BankLabel )
[void]$info.add( "    #   插槽    : $( $memory.DeviceLocator )" )
[void]$info.add( "        品牌    : $( $memory.Manufacturer )" )
[void]$info.add( "        序列号  : $( $memory.SerialNumber )" )
[void]$info.add( "        容量    : $( $memory.Capacity / 1GB ) GB" )
[void]$info.add( "        最高频率: $( $memory.Speed )" )
}
[void]$info.add( "" )
}
# 获取硬盘信息
function Get_Info_Disk() {
$diskInfo = Get-CimInstance -ClassName Win32_DiskDrive | Where-Object { $_.MediaType -eq 'Fixed hard disk media' }
foreach ($disk in $diskInfo) {
$physicalDisk = Get-PhysicalDisk | Where-Object { ('\\.\PHYSICALDRIVE' + $_.DeviceID ) -eq $disk.DeviceID }
Add-Member -InputObject $disk -MemberType NoteProperty -Name BusType -Value $physicalDisk.BusType
}
[void]$info.add( "硬盘:【 $( ($diskInfo | Measure-Object).Count ) 】" )
foreach ($disk in $diskInfo) {
[void]$info.add( "    #   DeviceID: $( $disk.DeviceID )" )
[void]$info.add( "        BusType : $( $disk.BusType )" )
[void]$info.add( "        型号    : $( $disk.Model )" )
[void]$info.add( "        序列号  : $( $disk.SerialNumber )" )
[void]$info.add( "        容量    : $( [int]($disk.Size / 1GB) ) GB" )
}
[void]$info.add( "" )
}
# 获取显示信息
function Get_Info_Video() {
$videoInfo = Get-CimInstance -ClassName Win32_VideoController
[void]$info.add( "显示适配器:" )
foreach ($video in $videoInfo) {
[void]$info.add( "    #   名称      : " + $video.Name )
[void]$info.add( "        显存      : " + $( $video.AdapterRAM / 1GB ) + " GB" )
[void]$info.add( "        当前刷新率: " + $video.CurrentRefreshRate )
[void]$info.add( "        最高刷新率: " + $video.MaxRefreshRate )
[void]$info.add( "        当前分辨率: " + $video.VideoModeDescription )
}
[void]$info.add( "" )
}
# 获取网卡信息
function Get_Info_NetAdapter() {
$nicInfo = Get-NetAdapter -Physical
[void]$info.add( "网络适配器:【 $( ($nicInfo | Measure-Object).Count ) 】" )
foreach ( $nic in $nicInfo ) {
[void]$info.add( "    #   名称      : $( $nic.DriverDescription )" )
[void]$info.add( "        MacAddress: $( $nic.MacAddress )" )
}
[void]$info.add( "" )
}
# 获取BIOS信息
function Get_Info_BIOS() {
$biosInfo = Get-CimInstance -ClassName Win32_BIOS
[void]$info.add( "BIOS:" )
[void]$info.add( "    制造商    : " + $biosInfo.Manufacturer )
[void]$info.add( "    名称      : " + $biosInfo.Name )
[void]$info.add( "    版本      : " + $biosInfo.Version )
[void]$info.add( "    BIOS  版本: " + $biosInfo.BIOSVersion )
[void]$info.add( "    SMBIOS版本: " + $biosInfo.SMBIOSBIOSVersion )
[void]$info.add( "    固件日期  : " + $biosInfo.ReleaseDate.ToString('yyyy-MM-dd') )
[void]$info.add( "    序列号    : " + $biosInfo.SerialNumber )
[void]$info.add( "" )
}
$info = [System.Collections.ArrayList]@()
Get_CurrentDateTime
Get_Info_system
Get_Info_Product
Get_Info_BaseBoard
Get_Info_BIOS
Get_Info_Processor
Get_Info_Memory
Get_Info_Disk
Get_Info_NetAdapter
Get_Info_Video
$info | Out-File "info.txt"
pauseCOPY
2

评分人数

回复 1# newswan

感谢分享,但俺不懂powershell,测试时有如下提示:

硬件信息(powershell).ps1 : 无法将“硬件信息(powershell).ps1”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请
检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ 硬件信息(powershell).ps1
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (硬件信息(powershell).ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

TOP

回复 2# hfxiang


保存为文件,编码 utf-16 le,右键运行

TOP

回复 3# newswan

测试成功,感谢

TOP

4090 显存 显示4G ?

TOP

这确实是个好思路

TOP

返回列表