Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 1.0 » Add-Member

Add-Member - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Add-Member

Description
Add a member to an instance of a PowerShell object

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

Options
-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.

CommonParameters
        Supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable.

Example(s)
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