将此段代码INVOKE到指定电脑,返回一个硬件清单,不同环境可能会有很多错误信息,比如存在多块网卡同时启用的情况,需要跟据环境微调
#获取网卡信息,只获取物理网卡,只获取有IP配置信息的网卡 function GetAdapterConfiguration{ $物理网卡=Get-WmiObject -Query "select MACAddress from Win32_NetworkAdapter where PNPDeviceID like 'PCI%'"|SELECT -ExpandProperty MACAddress foreach($item in $物理网卡){ Get-WmiObject -Query "select * from Win32_NetworkAdapterConfiguration where MACAddress='$item' and IPEnabled=true"|SELECT -Property *|select -Property IPAddress,IPSubnet,MACAddress,DefaultIPGateway,DNSServerSearchOrder,Description } } $网卡信息=GetAdapterConfiguration $系统信息=Get-WmiObject -Query "SELECT * FROM Win32_OperatingSystem" |select -Property OSArchitecture,Caption,CSName $CPU=Get-WmiObject -Query "SELECT * FROM Win32_Processor" |select -Property Name,Manufacturer,MaxClockSpeed,NumberOfCores,NumberOfLogicalProcessors $主板信息=Get-WmiObject -Query "SELECT * FROM Win32_baseboard"|select -Property Product,Manufacturer $硬盘信息=Get-WmiObject -Query "SELECT * from Win32_DiskDrive"|select -Property Caption,Size $系统盘信息=Get-WmiObject -Query "SELECT * from Win32_LogicalDisk where DriveType=3 and DeviceID='C:'"|select DeviceID,@{name="Size";e={($_.Size/1gb) -as [int]}},@{name="freespace";e={($_.freespace/1gb) -as [int]}} $内存信息=Get-WmiObject -Query "SELECT * from Win32_PhysicalMemory "|select -Property Manufacturer,DeviceLocator,Capacity $显卡名称=Get-WmiObject -Query "SELECT * from Win32_VideoController where PNPDeviceID like 'PCI%'"|SELECT -Property Name #-------------------------------------------------------分割线------------------------------------------------------------------------- $Computer= New-Object PSobject $Computer|Add-Member -MemberType NoteProperty -Name 计算机名 -Value $系统信息.CSName $Computer|Add-Member -MemberType NoteProperty -Name IP地址 -Value $网卡信息.IPAddress[0] $Computer|Add-Member -MemberType NoteProperty -Name 子网俺码 -Value $网卡信息.IPSubnet[0] $Computer|Add-Member -MemberType NoteProperty -Name 网关 -Value $网卡信息.DefaultIPGateway[0] $Computer|Add-Member -MemberType NoteProperty -Name DNS -Value $网卡信息.DNSServerSearchOrder[0] $Computer|Add-Member -MemberType NoteProperty -Name MAC地址 -Value $网卡信息.MACAddress $Computer|Add-Member -MemberType NoteProperty -Name 网卡名称 -Value $网卡信息.Description $Computer|Add-Member -MemberType NoteProperty -Name 操作系统 -Value $系统信息.Caption $Computer|Add-Member -MemberType NoteProperty -Name 系统架构 -Value $系统信息.OSArchitecture $Computer|Add-Member -MemberType NoteProperty -Name CPU名称 -Value $CPU.Name $Computer|Add-Member -MemberType NoteProperty -Name CPU频率 -Value $CPU.MaxClockSpeed $Computer|Add-Member -MemberType NoteProperty -Name CPU核心 -Value $CPU.NumberOfCores $Computer|Add-Member -MemberType NoteProperty -Name CPU线程 -Value $CPU.NumberOfLogicalProcessors $Computer|Add-Member -MemberType NoteProperty -Name 主板 -Value $主板信息.Product $Computer|Add-Member -MemberType NoteProperty -Name '系统盘可用空间(GB)' -Value $系统盘信息.freespace #处理存在多块硬盘的情况! $disk="" if($硬盘信息 -is [array]){ for($i=0;$i -lt $硬盘信息.Count;$i++) { $disk+= ($硬盘信息[$i].Caption)+"("+ ($硬盘信息[$i].Size/1000000000 -as [int])+"GB) " } }else{ $disk=$硬盘信息.Caption+"("+($硬盘信息.Size/1000000000 -as [int])+"GB)" } $Computer|Add-Member -MemberType NoteProperty -Name 硬盘信息 -Value $disk #处理多条内存条的情况 $Memory="" $allSize=0 if($内存信息 -is [array]){ foreach($item in $内存信息){ $Memory+="插槽:"+$item.DeviceLocator+" 容量:"+$item.Capacity/1gb+"GB 厂商:"+$item.Manufacturer $allSize+=$item.Capacity/1gb } }else{ $Memory="插槽:"+$内存信息.DeviceLocator+" 容量:"+$内存信息.Capacity/1gb+"GB 厂商:"+$内存信息.Manufacturer $allSize+=$内存信息.Capacity/1gb } $Computer|Add-Member -MemberType NoteProperty -Name '内存(GB)' -Value $allSize $Computer|Add-Member -MemberType NoteProperty -Name 内存详细信息 -Value $Memory $Computer|Add-Member -MemberType NoteProperty -Name 显卡 -Value $显卡名称.Name $Computer|Add-Member -MemberType NoteProperty -Name PowerShell版本 -Value $PSVersionTable.PSVersion #$Computer|Out-GridView $computer