Object Properties

This topic contains 2 replies, has 2 voices, and was last updated by  Sayed Hussein Mahdi 8 months, 3 weeks ago.

  • Author
    Posts
  • #61048

    Sayed Hussein Mahdi
    Participant

    Hi all,

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

    thanks

  • #61050

    Matt Bloomfield
    Participant

    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
    on
    
        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);}
  • #61087

    Sayed Hussein Mahdi
    Participant

    Thanks 🙂

You must be logged in to reply to this topic.