Element Type in PowerShell (ScriptProperty, Property, and NoteProperty)

What types of elements are in PowerShell such as ScriptProperty, Property, Method, NoteProperty, Alias, and EventProperty?

For example, the CPU is ScriptProperty. How can we classify it as ScriptProperty?

I would like to receive a brief information about all of them.

+9
source share
2 answers

There used to be a wonderful introduction to MSDN in the extended PowerShell type system (unfortunately, lost with changes from PSH v1).

In essence, PowerShell allows you to wrap a basic .NET object with additional members using PSObject . There are several ways to do this:

  • Using Add-Member (providing maximum control)
  • Specifying additional properties by passing a hash rather than a name in the Select-Object property parameter
  • Using New-Object to create a PSObject and transfer
  • In .NET code (C #, VB, ...), using the basic properties of the PSObject and PSMemberInfo subtypes.

Various types of "extended" elements are represented by these subtypes of PSMemberInfo , including:

  • NoteProperty: An object or .NET value.
  • AliasProperty: an alias for another property (for example, a collection can have both a Count property and a length, and the other can be different).
  • ScriptProperty: a property with get and set methods written in PowerShell.
  • CodeProperty: a property with get and set methods written in C #, VB, ....

etc.

+13
source

Source: https://habr.com/ru/post/958062/


All Articles