Object Properties

Hi all,

Please forgive my ignorance, but what is the difference between object’s property, NoteProperty and ScriptProperty?


A NoteProperty is a property with a name-value pair. A ScriptProperty is a property that uses PowerShell commands to calculate the property value.

This is a little clearer if you look at the output from Get-Member to see the property definitions:

PS E:\__Temp> Get-Item test.txt | Get-Member -MemberType NoteProperty,ScriptProperty | Select-Object MemberType,Definit

    MemberType Definition
    ---------- ----------
  NoteProperty string PSChildName=test.txt
  NoteProperty PSDriveInfo PSDrive=E
  NoteProperty bool PSIsContainer=False
  NoteProperty string PSParentPath=Microsoft.PowerShell.Core\FileSystem::E:\__Temp
  NoteProperty string PSPath=Microsoft.PowerShell.Core\FileSystem::E:\__Temp\test.txt
  NoteProperty ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem
ScriptProperty System.Object BaseName {get=if ($this.Extension.Length -gt 0){$this.Name.Remove($this.Name.Length - $...
ScriptProperty System.Object VersionInfo {get=[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName);}

Thanks :slight_smile: