PoshCode Archive  Artifact [b91d67ffe8]

Artifact b91d67ffe885f435b6ff17b454e906b81f66e32882d7398b02cbd9c5670bebf6:

  • File Get-FreeRAM.ps1 — part of check-in [53025af1c6] at 2018-06-10 13:17:45 on branch trunk — Get the Free RAM from a system (user: Joel Bennett size: 1279)

# encoding: ascii
# api: powershell
# title: Get-FreeRAM
# description: Get the Free RAM from a system
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Get-FreeRam
# x-poshcode-id: 2962
# x-archived: 2011-11-05T18:06:22
# x-published: 2011-09-21T09:58:00
#
# I wrote this just to show how to write WMI functions that work on multiple computers — note the difference between this script and it’s predecessor is just which WMI object and property are being returned
#
function Get-FreeRam {
#.Synopsis
#  Gets the FreePhysicalMemory from the specified computer(s)
#.Parameter ComputerName
#  The name(s) of the computer(s) to get the Free Ram (FreePhysicalMemory) for.
#.Example
#   Get-FreeRam SDI-JBennett, Localhost
#
# Computer              FreePhysicalMemory
# --------              ------------------
# SDI-JBENNETT                     4180364
# SDI-JBENNETT                     4179764
[CmdletBinding()]
param(
  [Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
  [string[]]$ComputerName='localhost'
)
process {
  Get-WmiObject -ComputerName $ComputerName Win32_OperatingSystem |
  Select-Object -Property @{name="Computer";expression={$_.__SERVER}}, FreePhysicalMemory
}
}