PowerShell/docs/check-ram.md

102 lines
2.5 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *check-ram.ps1* Script
===========================
2022-11-17 20:02:26 +01:00
check-ram.ps1
2022-11-17 19:46:02 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2022-11-17 19:46:02 +01:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
2023-09-01 17:53:03 +02:00
Checks the RAM
2022-11-17 20:02:26 +01:00
.DESCRIPTION
2023-09-01 17:53:03 +02:00
This PowerShell script queries the status of the installed RAM memory modules and prints it.
2022-11-17 20:02:26 +01:00
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./check-ram.ps1
2024-08-15 09:51:46 +02:00
✅ 16GB DDR4 RAM at 3200MHz/1.2V in CPU0/CPU0-DIMM3 by Micron
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function GetRAMType { param([int]$Type)
switch($Type) {
2 { return "DRAM" }
5 { return "EDO RAM" }
6 { return "EDRAM" }
7 { return "VRAM" }
8 { return "SRAM" }
10 { return "ROM" }
2023-05-26 12:20:18 +02:00
11 { return "Flash" }
2022-11-17 20:02:26 +01:00
12 { return "EEPROM" }
13 { return "FEPROM" }
14 { return "EPROM" }
15 { return "CDRAM" }
16 { return "3DRAM" }
17 { return "SDRAM" }
18 { return "SGRAM" }
19 { return "RDRAM" }
20 { return "DDR RAM" }
21 { return "DDR2 RAM" }
22 { return "DDR2 FB-DIMM" }
24 { return "DDR3 RAM" }
26 { return "DDR4 RAM" }
27 { return "DDR5 RAM" }
28 { return "DDR6 RAM" }
29 { return "DDR7 RAM" }
default { return "RAM" }
}
}
2023-05-26 12:20:18 +02:00
function Bytes2String { param([int64]$Bytes)
if ($Bytes -lt 1024) { return "$Bytes bytes" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)KB" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)MB" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)GB" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)TB" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)PB" }
$Bytes /= 1024
if ($Bytes -lt 1024) { return "$($Bytes)EB" }
}
2022-11-17 20:02:26 +01:00
try {
if ($IsLinux) {
# TODO
} else {
$Banks = Get-WmiObject -Class Win32_PhysicalMemory
foreach ($Bank in $Banks) {
2023-05-26 12:20:18 +02:00
$Capacity = Bytes2String($Bank.Capacity)
2022-11-17 20:02:26 +01:00
$Type = GetRAMType $Bank.SMBIOSMemoryType
$Speed = $Bank.Speed
[float]$Voltage = $Bank.ConfiguredVoltage / 1000.0
$Manufacturer = $Bank.Manufacturer
$Location = "$($Bank.BankLabel)/$($Bank.DeviceLocator)"
2024-08-15 09:51:46 +02:00
Write-Host "✅ $Capacity $Type at $($Speed)MHz,$($Voltage)V in $Location by $Manufacturer"
2022-11-17 20:02:26 +01:00
}
}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:51)*