Update calculation of RAM size #15

Open
opened 2022-03-17 10:56:02 -04:00 by efrick · 0 comments
Owner

The current function Find-RAM currently reads:

function Find-RAM { #This finds the systems total physical memory and then returns this as a value in Gigabytes.
    
    $cs = Get-CimInstance -ClassName win32_computersystem

    $system_memory = $cs.totalphysicalmemory

    $system_memory = $system_memory * 0.000000001 #Multiplies by 0.000000001 as the number give by CIM is in bytes.
    $system_memory = [math]::floor($system_memory)
    $system_memory = [String]$system_memory + " GB"

    return $system_memory
}

It would be better to use [math]::Round for this calculation.
The function would be:

function Find-RAM { #This finds the systems total physical memory and then returns this as a value in Gigabytes.
    
    $cs = Get-CimInstance -ClassName win32_computersystem

    $system_memory = $cs.totalphysicalmemory

    $system_memory = [math]::Round($system_memory / 1GB, 2)
    $system_memory = [String]$system_memory + " GB"

    return $system_memory
}

This should solve an issue with odd RAM values sometimes returning incorrect values.

The current function `Find-RAM` currently reads: ```powershell function Find-RAM { #This finds the systems total physical memory and then returns this as a value in Gigabytes. $cs = Get-CimInstance -ClassName win32_computersystem $system_memory = $cs.totalphysicalmemory $system_memory = $system_memory * 0.000000001 #Multiplies by 0.000000001 as the number give by CIM is in bytes. $system_memory = [math]::floor($system_memory) $system_memory = [String]$system_memory + " GB" return $system_memory } ``` It would be better to use `[math]::Round` for this calculation. The function would be: ```powershell function Find-RAM { #This finds the systems total physical memory and then returns this as a value in Gigabytes. $cs = Get-CimInstance -ClassName win32_computersystem $system_memory = $cs.totalphysicalmemory $system_memory = [math]::Round($system_memory / 1GB, 2) $system_memory = [String]$system_memory + " GB" return $system_memory } ``` This should solve an issue with odd RAM values sometimes returning incorrect values.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: efrick/Sysinfo#15
No description provided.