Monday, July 9, 2012

PowerShell (v3) : Test Memory Architecture

Three simple functions I saw the basis of a few ways back. Nothing special. Just good for reference. To test if a system is x86, run this:
function Isx86
{
      switch([IntPtr]::Size)
      {
            4
            {
                  $true
            }
            8
            {
                  $false
            }
      }
}
To test if a system is x64, use this approach:
function Isx64
{<.o:p>
      switch([IntPtr]::Size)
      {
        $26nbsp;   4
            {
                  $false
            }
            8
            {
                  $true
            }
      }
}
Another way to approach it:
function Get-ProcessorBitWidth
{
      switch([IntPtr]::Size)
      {
            2
            {
                  return '16'
            }
            4
            {
                  return '32'
            }
            8
            {
                  return '64'
            }
      }
}
Much more complex tricks can be done, but, these are good to know about.