Add a user-defined custom member to a PowerShell object instance.

      Add-Member [-memberType PSMemberType] 
	      [-name] string 
           [[-value] Object] [[-secondValue] Object]
               -inputObject psobject 
                 [-force] [-passThru] [CommonParameters]

   -memberType PSMemberType
        The type of the member to add. Valid values for this are:
        {AliasProperty | CodeProperty| Property | NoteProperty | ScriptProperty
       | Properties | PropertySet | Method | CodeMethod | ScriptMethod | Methods
       | ParameterizedProperty | MemberSet | All}

   -inputObject psobject
        The object to which the new member is added. (Required)
        Enter a variable that contains the objects or type a command or 
        expression that gets the objects.

   -name string
        The name of the member to be added.

   -value Object
        The initial value of the added member. If you add an AliasProperty,
        CodeProperty or CodeMethod member, you can supply optional, addi
        tional information by using the -SecondValue parameter.

   -force SwitchParameter
        Adds a new member even if one with the same name already exists. Does not
        work for core members of a type.

   -passThru SwitchParameter
        Pass the newly-extended object created by this cmdlet along the pipeline.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

You can only add members to PSObjects. To determine if a object is a PS Object, use the 'is' operator.
For example, to test an object stored in the $obj variable, type "$obj -is [PSObject]".

The names of the MemberType, Name, Value, and SecondValue parameters are optional. If you include the parameter names, the parameters can appear in any order. If you omit the parameter names, the unnamed parameter values must appear in this order: MemberType, Name, Value, SecondValue.

When specifying multiple values for a parameter, use commas to separate the values: "parameter-name value1, value2".


AliasProperty: A property that defines a new name for an existing property.
CodeMethod: A method that references a static method of a Microsoft .NET Framework class.
CodeProperty: A property that references a static property of a .NET Framework class.
MemberSet: A predefined collection of properties and methods, such as PSBase, PSObject, and PSTypeNames.
Method: A method of the underlying .NET Framework object.
NoteProperty: A property with a static value.
ParameterizedProperty: A property that takes parameters and parameter values.
Property: A property of the underlying .NET Framework object.
PropertySet: A predefined collection of object properties.
ScriptMethod: A method whose value is the output of a script.
ScriptProperty: A property whose value is the output of a script.

Methods: Gets all types of methods of the object
Properties: Gets all types of properties of the object


Add a note property to a DirectoryInfo object returned by Get -ChildItem.

PS C:>$a = (get-childitem)[0]      
 $a | add-member -membertype noteproperty -name MyNote -value SomeSampleText 
 $a | get-member

The above names a new property MyNote and assigns it the value: SomeSampleText.
Piping the updated object to Get-Member demonstrates that the property has been added.
For more examples run get-help Add-Member -detailed

"What we think, we become" - Siddhartha Gautama (Buddha)



© Copyright 1999-2014
Some rights reserved