stash/Get-PhysMemoryInfo.ps1

function Get-PhysMemoryInfo {
  [CmdletBinding()]param()

  process {
    New-Delegate ntdll {
      int NtQuerySystemInformation([int, buf, int, buf])
    }

    $buf = [Byte[]]::new(0x18) # sizeof(SYSTEM_PHYSICAL_MEMORY_INFORMATION)
    if (($nts = $ntdll.NtQuerySystemInformation.Invoke(
      184, $buf, $buf.Length, $null # x86 and x64 have the same structure length
    )) -ne 0) {
      Write-Verbose (ConvertTo-ErrMessage -NtStatus $nts)
      return
    }

    $total, $lowest, $highest = Read-DataValues $buf -Map L3
    format-List -InputObject ([PSCustomObject]@{
      TotalPhysicalBytes = $total
      LowestPhysicalAddress = "0x{0:X$([IntPtr]::Size * 2)}" -f $lowest
      HighestPhysicalAddress = "0x{0:X$([IntPtr]::Size * 2)}" -f $highest
    })
  }
}