# encoding: ascii
# api: powershell
# title: Compare-Property.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# type: script
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2132
# x-archived: 2016-05-17T12:49:30
# x-published: 2011-09-09T21:40:00
#
#
##############################################################################
##
## Compare-Property
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################
<#
.SYNOPSIS
Compare the property you provide against the input supplied to the script.
This provides the functionality of simple Where-Object comparisons without
the syntax required for that cmdlet.
.EXAMPLE
Get-Process | Compare-Property Handles gt 1000
.EXAMPLE
PS >Set-Alias ?? Compare-Property
PS >dir | ?? PsIsContainer
#>
param(
## The property to compare
$Property,
## The operator to use in the comparison
$Operator = "eq",
## The value to compare with
$MatchText = "$true"
)
Begin { $expression = "`$_.$property -$operator `"$matchText`"" }
Process { if(Invoke-Expression $expression) { $_ } }