Created
July 27, 2014 14:04
-
-
Save Nora-Ballard/8b11152135fd328dce11 to your computer and use it in GitHub Desktop.
Will only pass down the pipeline if the object, or object property has changed from the previous value. Useful for monitoring the status of a system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Select-OnChange { | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
$InputObject, | |
[Parameter()] | |
$PropertyName | |
) | |
PROCESS { | |
if ($PSBoundParameters.ContainsKey('PropertyName')) { | |
if ($LastValue.$PropertyName -ne $InputObject.$PropertyName) { | |
Write-Output $InputObject | |
} | |
} | |
else { | |
if ($LastValue -ne $InputObject) { | |
Write-Output $InputObject | |
} | |
} | |
$LastValue = $InputObject | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment