# getRamSlotsAvailable.ps1

$computername=$env:computername

function getRamSlotsAvailable{
    param($computername=$env:computername)
    write-host "Computer name: $computerName"
    $slots = Get-WmiObject -Class "win32_PhysicalMemoryArray" -namespace "root\CIMV2" -computerName $computerName
    $ramModules = Get-WmiObject -Class "win32_PhysicalMemory" -namespace "root\CIMV2" -computerName $computerName
    $ramSum=0
    $ramModules.Capacity|%{$ramSum+=$_}
    $slotsSum=0
    $slots.MemoryDevices|%{$slotsSum+=$_}
    write-host "Total slots: $slotsSum"
    write-host "Total RAM: $([math]::round($ramSum/1GB,2)) GB"
    Foreach ($module In $ramModules) {
        write-host "Memory Installed: $($module.DeviceLocator)"
        write-host "Memory Size: $($module.Capacity/1GB) GB"
    }
    return $slotsSum
}

getRamSlotsAvailable $computername

# Sample output
# PS C:\Windows\system32> getRamSlotsAvailable $computername
# Computer name: TEST-SERVER
# Total slots: 24
# Total RAM: 256 GB
# Memory Installed: DIMM_A1
# Memory Size: 16 GB
# Memory Installed: DIMM_A2
# Memory Size: 16 GB
# Memory Installed: DIMM_A3
# Memory Size: 16 GB
# Memory Installed: DIMM_A4
# Memory Size: 16 GB
# Memory Installed: DIMM_A5
# Memory Size: 16 GB
# Memory Installed: DIMM_A6
# Memory Size: 16 GB
# Memory Installed: DIMM_A7
# Memory Size: 16 GB
# Memory Installed: DIMM_A8
# Memory Size: 16 GB
# Memory Installed: DIMM_B1
# Memory Size: 16 GB
# Memory Installed: DIMM_B2
# Memory Size: 16 GB
# Memory Installed: DIMM_B3
# Memory Size: 16 GB
# Memory Installed: DIMM_B4
# Memory Size: 16 GB
# Memory Installed: DIMM_B5
# Memory Size: 16 GB
# Memory Installed: DIMM_B6
# Memory Size: 16 GB
# Memory Installed: DIMM_B7
# Memory Size: 16 GB
# Memory Installed: DIMM_B8
# Memory Size: 16 GB