# ************************************************************************** # # Copyright (c) SAPIEN Technologies, Inc. All rights reserved # This file is part of the PrimalScript 2007 Code Samples. # # File: showprocessinfo.ps1 # # Comments: # Display process information and flag those processes that # exceed the specified threshold in RED # usage: .\showprocessinfo computername memorythreshold_in_bytes # example: .\showprocessinfo . 1024000 # # Disclaimer: This source code is intended only as a supplement to # SAPIEN Development Tools and/or on-line documentation. # See these other materials for detailed information # regarding SAPIEN code samples. # # THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY # KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A # PARTICULAR PURPOSE. # # ************************************************************************** Param([string] $strComputer,[int] $MemoryThreshhold) $colItems = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2" ` -computername $strComputer foreach ($objItem in $colItems) { if ($objItem.WorkingSetSize -gt $MemoryThreshhold) { write-host $objItem.Name $objItem.WorkingSetSize -foregroundcolor "red" } else {write-host $objItem.Name $objItem.WorkingSetSize} } }