Skip to main content

Describing Object Properties

Today we are going to look at a member of an object called a property.  Simply put, a property describes something. Take your phone for instance.  Let’s identify several properties. 
  •         Color
  •         Make
  •         Model
  •         Operating System
  •         Memory


Every cell phone on the market would have these properties, but we all know the value of these properties will not be the same.  Here are mine:
Property
Value
Color
Black
Make
Samsung
Model
Galaxy 7
Operating System
Android
Memory
32GB

Does your phone’s property values match mine? Most likely not.  Since your phone has the same properties as mine, we can make a safe assumption that it is an object of type Cell Phone.  Let’s go with our example from yesterday and take a look at the properties of a volume.  We are going to use the cmdlet Get-Member to show us all of the properties in the object produced by Get-Volume
PS C:\> Get-Volume | Get-Member -MemberType Properties


   TypeName:
Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume

Name                 MemberType     Definition                                           
----                 ----------     ----------                                            
AllocationUnitSize   Property       uint32 AllocationUnitSize {get;}                     
DriveLetter          Property       char DriveLetter {get;}                              
FileSystem           Property       string FileSystem {get;}                             
FileSystemLabel      Property       string FileSystemLabel {get;set;}                    
ObjectId             Property       string ObjectId {get;}                                
PassThroughClass     Property       string PassThroughClass {get;}                       
PassThroughIds       Property       string PassThroughIds {get;}                         
PassThroughNamespace Property       string PassThroughNamespace {get;}                   
PassThroughServer    Property       string PassThroughServer {get;}                      
Path                 Property       string Path {get;}                                   
PSComputerName       Property       string PSComputerName {get;}                         
Size                 Property       uint64 Size {get;}                                   
SizeRemaining        Property       uint64 SizeRemaining {get;}                          
UniqueId             Property       string UniqueId {get;}                               
DedupMode            ScriptProperty System.Object DedupMode {get=switch ($this.psBase.C...
DriveType            ScriptProperty System.Object DriveType {get=switch ($this.psBase.C...
FileSystemType       ScriptProperty System.Object FileSystemType {get=switch ($this.psB...
HealthStatus         ScriptProperty System.Object HealthStatus {get=switch ($this.psBas...
OperationalStatus    ScriptProperty System.Object OperationalStatus {get=$_status = @()...

There are actually 4 different property types that you may come across.  The way how to property was created determines what type of property it is.

NoteProperty: A .NET object.

AliasProperty: An alias for another property.

ScriptProperty: A property with get and set methods written in PowerShell.

CodeProperty: A property with get and set methods written in C#, VB.

A script property is one where you can actually see the code that determined the value of the property.  Take a look at our Get-Volume example.
PS C:\> Get-Volume

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining      Size
----------- --------------- ---------- --------- ------------ ----------------- -------------      ----
                            NTFS       Fixed     Healthy      OK                     99.03 MB    450 MB
                            NTFS       Fixed     Healthy      OK                    321.21 MB    350 MB
E           DATA            NTFS       Fixed     Healthy      OK                     21.73 GB 238.34 GB
D           DATA            NTFS       Fixed     Healthy      OK                     19.99 GB 238.34 GB
            WINRETOOLS      NTFS       Fixed     Healthy      OK                    212.47 MB    492 MB
C           OS              NTFS       Fixed     Healthy      OK                      5.06 GB 108.29 GB
            PBR Image       NTFS       Fixed     Healthy      OK                     243.9 MB   9.03 GB

Notice the value of DriveType.  The word “Fixed” is not stored as part of the data. It is actually the integer value of 3. This is because there is a defined list of acceptable values for this property and storing a number, as opposed to a string, is more memory efficient.  Take a look at this definition of this ScriptProperty.

PS C:\> Get-Volume | Get-Member -Name Drivetype | Select-Object -ExpandProperty Definition
System.Object DriveType {get=switch ($this.psBase.CimInstanceProperties["DriveType"].Value)

          {
          0 { "Unknown" }
          1 { "Invalid Root Path" }
          2 { "Removable" }
          3 { "Fixed" }
          4 { "Remote" }
          5 { "CD-ROM" }
          6 { "RAM Disk" }
          Default { "Unknown" }
          };}

Let’s ask the Object of Get-Volume to give us it’s TypeName
PS C:\> Get-Volume | Get-Member | Select-Object -First 1 -Property TypeName

TypeName                                                                                 
--------                                                                                 
Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume


Going online and searching for MFST_Volume takes us to. https://msdn.microsoft.com/en-us/library/windows/desktop/hh830604(v=vs.85).aspx. Here is a screen shot of the DriveType property description. 

The data type for this property is an integer.  It is read only and it has 7 valid values.  The value of 3 represents a “Fixed” drive.

You will not be able to run Get-Help on an object to get information on what its members mean.  You will have to go to MSDN for that. To determine your search query for an objects information, use the TypeName.  If the TypeName contains a “\” like the one above, only query everything to the right of the final “\”.  In this case, MSFT_Volume. Look at the example below.

PS C:\> Get-Process | Get-Member | Select-Object -First 1 -Property TypeName

TypeName                 
--------                 
System.Diagnostics.Process

Since the TypeName does not contain any “\”, your query will be System.Diagnostics.Process.  You can also use my Show-MSDNResource cmdlet.  Make sure you read the setup instructions and help file.  You can get the cmdlet here.

You may also notice that the MSDN resources do not contain all of the properties that Get-Member displays.  That is because there are other cmdlets used in the process of collecting the information. These cmdlet add members to the object in the pipeline, but are not part of the original object. Here is the list of properties for MSFT_Volume on MSDN


Notice that it contains 10 properties.  Here is the result of Get-Volume | Get-Member.

PS C:\> Get-volume | Select-Object -Property * -First 1


OperationalStatus     : OK
HealthStatus          : Healthy
DriveType             : Fixed
FileSystemType        : NTFS
DedupMode             : NotAvailable
ObjectId              : {1}\\JASONPC2\root/Microsoft/Windows/Storage/Providers_v2\WSP_Volu
                        me.ObjectId="{c918366b-4c74-11e3-824f-806e6f6e6963}:VO:\\?\Volume{
                        463405a4-618b-43f5-a8d2-6279f60cf907}\"
PassThroughClass      :
PassThroughIds        :
PassThroughNamespace  :
PassThroughServer     :
UniqueId              : \\?\Volume{463405a4-618b-43f5-a8d2-6279f60cf907}\
AllocationUnitSize    : 4096
DriveLetter           :
FileSystem            : NTFS
FileSystemLabel       :
Path                  : \\?\Volume{463405a4-618b-43f5-a8d2-6279f60cf907}\
Size                  : 471855104
SizeRemaining         : 103841792
PSComputerName        :
CimClass              : ROOT/Microsoft/Windows/Storage:MSFT_Volume
CimInstanceProperties : {ObjectId, PassThroughClass, PassThroughIds,
                        PassThroughNamespace...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

It contains 22 properties.  Again, this is because PowerShell and the cmdlets used to get this information is adding their own information to the object as it passes through the pipeline.

You may also noticed that some values are NULL.  This is OK.  The reason for this is either new properties were added to this objects description (class) and your current technology does not support it or it is older properties that newer technology does not use.  In either case, it is OK.  PowerShell will not error.  It will just leave the value at NULL.

Comments

Popular posts from this blog

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.

How to run GPResult on a remote client with PowerShell

In the past, to run the GPResult command, you would need to either physically visit this client, have the user do it, or use and RDP connection.  In all cases, this will disrupt the user.  First, you need PowerShell remoting enabled on the target machine.  You can do this via Group Policy . Open PowerShell and type this command. Invoke-Command –ScriptBlock {GPResult /r} –ComputerName <ComputerName> Replace <ComputerName> with the name of the target.  Remember, the target needs to be online and accessible to you.

Error icon when creating a GPO Preference drive map

You may not have an error at all.  Take a look at the drive mapping below. The red triangle is what threw us off.  It is not an error.  It is simply a color representation of the Replace option of the Action field in the properties of the drive mappings. Create action This give you a green triangle. The Create action creates a new mapped drive for users. Replace Action The Replace action gives you a red triangle.  This action will delete and recreate mapped drives for users. The net result of the Replace action is to overwrite all existing settings associated with the mapped drive. If the drive mapping does not exist, then the Replace action creates a new drive mapping. Update Action The Update action will have a yellow triangle. Update will modify settings of an existing mapped drive for users. This action differs from Replace in that it only updates settings defined within the preference item. All other settings remain as configured on the ma...