Helpful Scripts

tanderson
tanderson Member Posts: 255 ✭✭✭✭

I made a script to help you understand more about a device's RAM than Atera's agent will show you. We use this to easily see the RAM size and speed and how many RAM slots are available/used. It's very nice for upsell purposes. It gives you some recommendations at the bottom of the output. Save this in your script library as a Powershell script.

Convert FormFactor to readable format

function Get-FormFactor {
param (
[int]$factor
)
switch ($factor) {
8 { return "DIMM" }
12 { return "SODIMM" }
default { return "Unknown" }
}
}

Retrieve and display RAM information

$memoryDetails = Get-WmiObject -Class "Win32_PhysicalMemory" | Select-Object BankLabel,
@ .Capacity / 1GB, 2)}}, DeviceLocator,
@{Name="Speed (MHz)";Expression={$
.Speed}}, Manufacturer,
PartNumber, `
@{Name="FormFactor";Expression={Get-FormFactor $_.FormFactor}}

$totalSlots = (Get-WmiObject -Class "Win32_PhysicalMemoryArray").MemoryDevices
$usedSlots = $memoryDetails.Count
$availableSlots = $totalSlots - $usedSlots

$memoryStatus = Get-WmiObject -Class "Win32_OperatingSystem"
$totalVisibleMemory = [math]::round($memoryStatus.TotalVisibleMemorySize / 1MB, 2)
$freePhysicalMemory = [math]::round($memoryStatus.FreePhysicalMemory / 1MB, 2)
$usedPhysicalMemory = $totalVisibleMemory - $freePhysicalMemory
$usedMemoryPercentage = [math]::round(($usedPhysicalMemory / $totalVisibleMemory) * 100, 2)

Write-Output "Memory Module Details:"
$memoryDetails | Format-Table -AutoSize
Write-Output "nTotal Number of DIMM Slots Available: $totalSlots"
Write-Output "Number of DIMM Slots Currently in Use: $usedSlots"
Write-Output "Number of DIMM Slots Available for Use: $availableSlots"
Write-Output "
nCurrent Memory Usage:"
Write-Output "Total Visible Memory: $totalVisibleMemory GB"
Write-Output "Used Physical Memory: $usedPhysicalMemory GB"
Write-Output "Free Physical Memory: $freePhysicalMemory GB"
Write-Output "Memory Usage: $usedMemoryPercentage%"
Write-Output "`n"

Recommendations based on memory usage and total installed memory

$recommendations = @()
if ($totalVisibleMemory -le 8) {
$recommendations += "Consider upgrading to at least 16 GB of RAM for better performance."
} elseif ($usedMemoryPercentage -ge 70) {
if ($totalVisibleMemory -lt 16) {
$recommendations += "Consider upgrading to at least 16 GB of RAM for better performance."
} else {
$recommendations += "Current RAM is sufficient for most tasks."
}
}

if ($recommendations.Count -eq 0) {
$recommendations += "No immediate upgrades are necessary."
}

Write-Output "Recommendations:"
$recommendations | ForEach-Object { Write-Output $_ }

Tagged:

Comments

  • tanderson
    tanderson Member Posts: 255 ✭✭✭✭

    For some devices, it doesn't pull all the info, and for some, it does, but it still gets the job done for knowing how much RAM there is, what the speed is, and how many slots are used/available.

  • Russ
    Russ Member Posts: 29

    Very nice! Thank you for generously sharing @tanderson. Much appreciated.

  • gilgi
    gilgi Administrator, Moderator, Internal Posts: 181 admin

    That's wonderful! Go @tanderson! 👏👏👏👏