PowerShell 获取系统信息 1


Powershell能非常方便的支持现有的控制台应用程序, 其中非常实用的systeminfo.exe程序,它能搜集各种有用的系统信息。通过systeminfo.exe导入获取的CSV格式数据,Powershell能将这些信息转换成丰富的对象:

$header = 'Hostname','OSName','OSVersion','OSManufacturer','OSConfig','Buildtype',`
'RegisteredOwner','RegisteredOrganization','ProductID','InstallDate','StartTime','Manufacturer',`
'Model','Type','Processor','BIOSVersion','WindowsFolder','SystemFolder','StartDevice','Culture',`
'UICulture','TimeZone','PhysicalMemory','AvailablePhysicalMemory','MaxVirtualMemory',`
'AvailableVirtualMemory','UsedVirtualMemory','PagingFile','Domain','LogonServer','Hotfix',`
'NetworkAdapter'
systeminfo.exe /FO CSV | 
  Select-Object -Skip 1 | 
  ConvertFrom-CSV -Header $header

当你执行了这个脚本,systeminfo.exe程序将需要几秒钟的时间搜集系统信息,然后你将获得丰富的系统信息。

1

 

#注释# $header: 这个变量定义了所需属性的名字和替换默认显示的标题 , 这种方式确保不管系统默认是哪种语言它们的标题总是一样。

你也可以将这些信息保存为一个变量并且访问它其中的个别属性:

$header = 'Hostname','OSName','OSVersion','OSManufacturer','OSConfig','Buildtype',`
'RegisteredOwner','RegisteredOrganization','ProductID','InstallDate','StartTime','Manufacturer',`
'Model','Type','Processor','BIOSVersion','WindowsFolder','SystemFolder','StartDevice','Culture',`
'UICulture','TimeZone','PhysicalMemory','AvailablePhysicalMemory','MaxVirtualMemory',`
'AvailableVirtualMemory','UsedVirtualMemory','PagingFile','Domain','LogonServer','Hotfix',`
'NetworkAdapter'$result = systeminfo.exe /FO CSV | Select-Object -Skip 1 | ConvertFrom-CSV -Header $header

2
原文链接:Getting System Information

本文链接: https://www.pstips.net/get-system-info.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

一条评论 “PowerShell 获取系统信息