PowerShell Function之获取ComputerSystem信息
2015-11-08 17:10
405 查看
这是PowerShell Function系列的第二篇,聊聊ComputerSystem的信息。别混淆了哈,上一篇讲的是Operatingsystem。会不会有人傻傻分不清?那么请下以下截图,有个初步的分类吧。
同样的,可以运行以下命令来看看Win32_ComputerSystem到底有哪些ExpandProperty。
有59个属性,属性太多了,本次我们只需要获取manufacturer,RAM,Sockets和Cores的信息。同样地,这些信息不能直接get出来,依然需要创建一个数组给他们添加输出的属性。直接上脚本吧。
以上是我的笔记本信息,可以通过以下截图对比看下信息是不是正确的。
最后,写成function
同样的,可以运行以下命令来看看Win32_ComputerSystem到底有哪些ExpandProperty。
Get-CimInstance Win32_ComputerSystem | select -ExpandProperty CimInstanceProperties | Export-Csv system.csv -NoTypeInformation -Encoding UTF8
有59个属性,属性太多了,本次我们只需要获取manufacturer,RAM,Sockets和Cores的信息。同样地,这些信息不能直接get出来,依然需要创建一个数组给他们添加输出的属性。直接上脚本吧。
$cs = Get-WmiObject -class Win32_ComputerSystem -ComputerName $ComputerName $props = @{'Model'=$cs.model; 'Manufacturer'=$cs.manufacturer; 'RAM (GB)'="{0:N2}" -f ($cs.totalphysicalmemory / 1GB); 'Sockets'=$cs.numberofprocessors; 'Cores'=$cs.numberoflogicalprocessors} New-Object -TypeName PSObject -Property $props
以上是我的笔记本信息,可以通过以下截图对比看下信息是不是正确的。
最后,写成function
unction Get-InfoCompSystem { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $cs = Get-WmiObject -class Win32_ComputerSystem -ComputerName $ComputerName $props = @{'Manufacturer'=$cs.manufacturer; 'RAM (GB)'="{0:N2}" -f ($cs.totalphysicalmemory / 1GB); 'Sockets'=$cs.numberofprocessors; 'Cores'=$cs.numberoflogicalprocessors} New-Object -TypeName PSObject -Property $props }
相关文章推荐
- Linux 控制台/终端/tty/shell
- 解决bash: mysql: command not found 的方法
- linux shell — 6.初识 EXT2 文件系统
- [Win32] ShellHook的实现
- Shell 脚本学习
- shell-排序
- shell-脚本安装第三方库
- shell正则表达式(zhuan)
- shell正则表达式(zhuan)
- PowerShell Function之获取OS信息
- Shell中date的用法
- PowerShell介绍 第十三回 定义参数
- win10 环境 gitbash 显示中文乱码问题处理
- 使用shell生成随机数
- 将shell命令保存为一个变量
- PowerShell介绍 第十二回 函数
- [Linux]bashrc和profile的学习
- PowerShell实战 第五回 创建HAB
- PowerShell实战 第三回 管理AD OU对象
- PowerShell实战 第二回 管理AD用户对象