Follow these instructions and paste the script into PowerShell to retrieve RAM information.

Step 1:
             Access PowerShell by searching for it in the Start menu or pressing win + r and typing "powershell".

            You can just copy paste the script in PowerShell but some users may encounter an issue with the PowerShell policy blocking script execution. To overcome this, follow these steps:

Step 2:
             Check your current execution policy to ensure you are aware of it. You can do this by running the following command:
Get-ExecutionPolicy

If the policy is "unrestricted", you can simply copy and paste the script to run it.

Step 3:
            Create a scoped execution policy for the session by executing the following command.
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

This policy only affects the current PowerShell session and does not alter the global policy.

Step 4:
             To execute your PowerShell script, you have two options.
                              You can copy and paste the script into the PowerShell window and execute it.
# Define lookup arrays for converting numeric values to human-readable descriptions
$FORM_FACTORS = @('Invalid', 'Other', 'Unknown', 'SIMM', 'SIP', 'Chip', 'DIP', 'ZIP', 'Proprietary Card', 'DIMM', 'TSOP', 'Row of chips', 'RIMM', 'SODIMM', 'SRIMM', 'FB-DIMM', 'Die')
$MEMORY_TYPES = @('Invalid', 'Other', 'Unknown', 'DRAM', 'EDRAM', 'VRAM', 'SRAM', 'RAM', 'ROM', 'FLASH', 'EEPROM', 'FEPROM', 'EPROM', 'CDRAM', '3DRAM', 'SDRAM', 'SGRAM', 'RDRAM', 'DDR', 'DDR2', 'DDR2 FB-DIMM', 'Reserved', 'Reserved', 'Reserved', 'DDR3', 'FBD2', 'DDR4', 'LPDDR', 'LPDDR2', 'LPDDR3', 'LPDDR4', 'Logical non-volatile device', 'HBM (High Bandwidth Memory)', 'HBM2 (High Bandwidth Memory Generation 2)', 'DDR5', 'LPDDR5')
$TYPE_DETAILS = @('Reserved', 'Other', 'Unknown', 'Fast-paged', 'Static column', 'Pseudo-static', 'RAMBUS', 'Synchronous', 'CMOS', 'EDO', 'Window DRAM', 'Cache DRAM', 'Non-volatile', 'Registered (Buffered)', 'Unbuffered (Unregistered)', 'LRDIMM')

# Define a function for looking up values in the arrays
function LookUp([string[]]$table, [int]$value) {
    if ($value -ge 0 -and $value -lt $table.Length) {
        return $table[$value]
    }
    return "Unknown value 0x{0:X}" -f $value
}

# Define a function to parse memory tables
function ParseMemoryTable([byte[]]$table, [int]$startIndex) {
    # Extract memory size information
    $size = [BitConverter]::ToUInt16($table, $startIndex + 0x0C)
    if ($size -eq 0xFFFF) {
        Write-Output "Unknown memory size"
    } else {
        # Convert size to GB if necessary
        $size = if ($size -shr 15 -eq 0) { $size * 1MB } else { $size * 1KB }
        Write-Output ("Size: {0:N0} bytes ({1:F2} GB)" -f $size, ($size / 1GB))
    }

    # Extract memory form factor information
    $formFactor = $table[$startIndex + 0x0E]
    Write-Output ("Memory form factor: 0x{0:X2} {1}" -f $formFactor, (LookUp $FORM_FACTORS $formFactor))

    # Extract memory type information
    $type = $table[$startIndex + 0x12]
    Write-Output ("Memory type: 0x{0:X2} ({1})" -f $type, (LookUp $MEMORY_TYPES $type))

    # Extract type details
    $typeDetail = [BitConverter]::ToUInt16($table, $startIndex + 0x13)
    $details = [System.Linq.Enumerable]::Range(0, 16) | Where { ($typeDetail -band (1 -shl $_)) -ne 0 } | ForEach-Object { $TYPE_DETAILS[$_] }
    Write-Output ("Type detail: 0x{0:X2} ({1})" -f $typeDetail, ($details -join ' | '))

    # Extract memory speed
    $speed = [BitConverter]::ToUInt16($table, $startIndex + 0x15)
    if ($speed -eq 0) {
        Write-Output "Unknown speed"
    } else {
        Write-Output ("Speed: {0:N0} MT/s" -f $speed)
    }

    Write-Output "======================="
}

# Fetch SMBIOS data using WMI
$BiosTables = (Get-WmiObject -ComputerName . -Namespace root\wmi -Query "SELECT SMBiosData FROM MSSmBios_RawSMBiosTables").SMBiosData

# Initialize variables for table parsing
$index = 0
$END_OF_TABLES = 127
$MEMORY_DEVICE = 17

# Parse the SMBIOS data
do {
    $startIndex = $index
    $tableType = $BiosTables[$index]

    # Check if this is the end of the SMBIOS tables
    if ($tableType -eq $END_OF_TABLES) {
        break
    }

    # Get the length of the current table
    $tableLength = $BiosTables[$index + 1]
    $index += $tableLength

    # Move to the end of the table (denoted by two null bytes)
    while ([BitConverter]::ToUInt16($BiosTables, $index) -ne 0) {
        $index++
    }
    $index += 2

    # Skip any trailing null bytes
    if ($BiosTables[$index] -eq 0) {
        $index++
    }

    # If the current table type is a memory device, call the parsing function
    if ($tableType -eq $MEMORY_DEVICE) {
        ParseMemoryTable $BiosTables $startIndex
    }
} while ($tableType -ne $END_OF_TABLES -and $index -lt $BiosTables.Length)
Alternatively, you can follow these steps to save and run the script.
To save the Script:
             1. Open a text editor like Notepad.
             2. Copy the entire PowerShell script from its original source.
             3. Paste the script into the text editor.
             4. Save the file with a .ps1 extension, such as MemoryInfoScript.ps1

To Execute the Script:
                    Navigate to the Script Location by using the PowerShell cd (Change Directory) command to go to the folder where you saved the .ps1 script.For example, if you saved it on your desktop, navigate to the desktop with this command  
cd $env:USERPROFILEDesktop

Execute the script by entering its name, including the .ps1 extension:
.MemoryInfoScript.ps1
Make sure to include the . before the script name to indicate it's in the current directory.

Step 5:
            Restore Execution Policy (Optional), If you changed the execution policy for the current session in Step 2, you can restore the previous policy by running this command:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy <PreviousPolicy>
Replace <PreviousPolicy> with your original execution policy.

Restoring it to its previous condition will not have any impact on the execution policy of future PowerShell sessions. The execution policy is a configuration setting that only applies to the current session. When you initiate a fresh PowerShell session, it will adhere to the system-wide or user-specific execution policy.


Comments (2)
Leave a Comment

loader Posting your comment...