Skip to content

Instantly share code, notes, and snippets.

@Nora-Ballard
Created July 27, 2014 14:04
Show Gist options
  • Save Nora-Ballard/8b11152135fd328dce11 to your computer and use it in GitHub Desktop.
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.
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