Properties are the data that is associated with an object. Different types of object have different properties. For example, a FileInfo object, which represents a file, has an IsReadOnly property that contains $True if the file the read-only attribute and $False if it does not. A DirectoryInfo object, which represents a file system directory, has a Parent property that contains the path to the parent directory.
To get the Properties of any object, use the Get-Member cmdlet. Use its MemberType property with a value of "property".
Get-ChildItem $pshome\PowerShell.exe | Get-Member -MemberType property TypeName: System.Diagnostics.Process TypeName: System.IO.FileInfo Name MemberType Definition ---- ---------- ---------- Attributes Property System.IO.FileAttributes Attributes {get;set;} CreationTime Property System.DateTime CreationTime {get;set;} CreationTimeUtc Property System.DateTime CreationTimeUtc {get;set;} Directory Property System.IO.DirectoryInfo Directory {get;} DirectoryName Property System.String DirectoryName {get;} Exists Property System.Boolean Exists {get;} Extension Property System.String Extension {get;} FullName Property System.String FullName {get;} IsReadOnly Property System.Boolean IsReadOnly {get;set;} LastAccessTime Property System.DateTime LastAccessTime {get;set;} LastAccessTimeUtc Property System.DateTime LastAccessTimeUtc {get;set;} LastWriteTime Property System.DateTime LastWriteTime {get;set;} LastWriteTimeUtc Property System.DateTime LastWriteTimeUtc {get;set;} Length Property System.Int64 Length {get;} Name Property System.String Name {get;}
The most common way to get the values of the properties of an object is to use the dot method.
$a = Get-ChildItem $pshome\PowerShell.exe $a.CreationTime (Get-ChildItem $pshome\PowerShell.exe).creationtime Tuesday, March 18, 2008 12:07:52 AM
You can also use the Select-Object and Format-List cmdlets to display the property values of an object.
Get-ChildItem $pshome\PowerShell.exe | Format-List -Property *
Static properties are properties of class, unlike standard properties, which are properties of an object.
To get the static properties of an class, use the Static parameter of the Get-Member cmdlet.
Get-Date | Get-Member -MemberType Property -Static TypeName: System.DateTime Name MemberType Definition ---- ---------- ---------- MaxValue Property static datetime MaxValue {get;} MinValue Property static datetime MinValue {get;} Now Property datetime Now {get;} Today Property datetime Today {get;} UtcNow Property datetime UtcNow {get;}
To get the value of a static property, use the following syntax.
[<ClassName>]::<Property> [System.DateTime]::UtcNow