Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Monitoring memory utilization


To retrieve memory information from local and remote computers using PowerShell, we can use WMI, or query performance counters. In this recipe, you'll learn a few techniques that can be used to monitor memory utilization using the Get-WmiObject cmdlet.

How to do it...

  1. To gather memory utilization with WMI, we need to query two separate classes:

    $OS = Get-WmiObject Win32_OperatingSystem
    $CS = Get-WmiObject Win32_ComputerSystem
  2. Next, we can access the free and total physical memory from each object:

  3. To convert the values to gigabytes, we need to use the mb and gb multipliers:

Now we can easily see that the local system has a total of 2 GB of RAM. If we subtract the FreePhysicalMemory from the TotalPhysicalMemory, we can determine that we're using about 1.8 GB of RAM on this machine.

How it works...

When working with the Win32_OperatingSystem class, the FreePhysicalMemory property is represented in kilobytes, as opposed to bytes. Therefore, when we calculate the size...