获取本机内存信息 4


今天在群里看到童鞋们在讨论使用Powershell获取内存信息,不才整理了下,发下博客。希望对后来者有所帮助!

#获取本机内存大小,单位为Gb,小数点后保留两位
$mem = "{0:N2}GB" -f (((Get-WmiObject -Class Win32_PhysicalMemory).capacity | Measure-Object -Sum).sum /1gb)
#获取本机内存条数
$slot = ((Get-WmiObject -Class Win32_PhysicalMemory).capacity | Measure-Object -Sum).count
#获取本机内存生产厂商
$Manufacturer = (Get-WmiObject -Class Win32_PhysicalMemory).Manufacturer
#获取本机空闲内存,单位Gb,小数点后保留两位
$freemem = "{0:N2}GB" -f ((Get-WmiObject -Class Win32_OperatingSystem).FreePhysicalMemory /1mb)
#打印结果
Write-Host "本机内存总计: $mem"
Write-Host "本机共 $slot 条内存" 
Write-Host "本机空闲内存 $freemem"
Write-Host "内存厂商 $Manufacturer"
本文链接: https://www.pstips.net/get-memory-info-from-localhost.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

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

4 条评论 “获取本机内存信息