Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created November 16, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/34194d3c4df40a5ae8bad0776094c9e5 to your computer and use it in GitHub Desktop.
Save vexx32/34194d3c4df40a5ae8bad0776094c9e5 to your computer and use it in GitHub Desktop.
# NoteProperty
$Object = [PSCustomObject]@{
Number = 10
Word = "Antimony"
}
$Object.Number = 12
$Object.Word # Outputs: Antimony # Doesn't change
$Object | Add-Member -MemberType ScriptProperty -Name Remainder -Value {$this.Number % 4}
$Object.Remainder # Outputs: 0
# And if the referenced property is changed...
$Object.Number = 11
$Object.Remainder # Outputs: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment