Object Properties

Welcome Forums General PowerShell Q&A Object Properties

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 years, 4 months ago.

  • Author
    Posts
  • #61048

    Participant
    Topics: 3
    Replies: 10
    Points: 0
    Rank: Member

    Hi all,

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

    thanks

  • #61050

    Participant
    Topics: 1
    Replies: 284
    Points: 41
    Rank: Member

    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

    Participant
    Topics: 3
    Replies: 10
    Points: 0
    Rank: Member

    Thanks 🙂

The topic ‘Object Properties’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort