Skip to content

Update Add-Member.md example layouts #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions reference/6/Microsoft.PowerShell.Utility/Add-Member.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ For more information, see the *PassThru* parameter description.
PS C:\> $A = dir c:\ps-test\test.txt
PS C:\> $A | Add-Member -NotePropertyName Status -NotePropertyValue Done
PS C:\> $A | Add-Member Status Done
PS C:\> $A.StatusDone
PS C:\> $A.Status
Done
```

These commands add the Status note property with a value of "Done" to the FileInfo object that represents the Test.txt file.
Expand All @@ -89,7 +90,8 @@ As the output shows, the value is "Done".
```
PS C:\> $A = dir c:\ps-test\test.txt
PS C:\> $A | Add-Member -MemberType AliasProperty -Name FileLength -Value Length
PS C:\> $A.FileLength2394
PS C:\> $A.FileLength
2394
```

These commands add the FileLength alias property to the object that represents the Test.txt file.
Expand All @@ -104,7 +106,8 @@ The third command uses dot notation to get the value of the new FileLength prope
### Example 3: Add a StringUse note property to a string
```
PS C:\> $A = "A string"PS C:\> $A = $A | Add-Member @{StringUse="Display"} -PassThru
PS C:\> $A.StringUseDisplay
PS C:\> $A.StringUse
Display
```

These commands add the **StringUse** note property to a string.
Expand Down Expand Up @@ -144,28 +147,16 @@ The third command uses dot notation to call the new PadBoth script method on the
PS C:\> $Event = Get-EventLog -LogName System -Newest 1
PS C:\> $Event.TimeWritten | Get-MemberTypeName: System.DateTime
Name MemberType Definition


---- ---------- ----------


Add Method System.DateTime Add(System.TimeSpan value)


AddDays Method System.DateTime AddDays(double value)


AddHours Method System.DateTime AddHours(double value)


AddMilliseconds Method System.DateTime AddMilliseconds(double value)


AddMinutes Method System.DateTime AddMinutes(double value)...


PS C:\> Add-Member -InputObject $Event -MemberType AliasProperty -Name When -Value TimeWritten -SecondValue System.String
PS C:\> $Event.When | Get-MemberTypeName: System.String

Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone()
Expand Down Expand Up @@ -492,18 +483,16 @@ When you use the *PassThru* parameter, this cmdlet returns the newly-extended ob
Otherwise, this cmdlet does not generate any output.

## NOTES
* You can add members only to PSObject objects. To determine whether an object is a PSObject object, use the "is" operator. For instance, to test an object stored in the $obj variable, type `$obj -is \[PSObject\]`.
You can add members only to PSObject objects. To determine whether an object is a PSObject object, use the "is" operator. For instance, 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.
The names of the *MemberType*, *Name*, *Value*, and *SecondValue* parameters are optional.
If you omit the parameter names, the unnamed parameter values must appear in this order: *MemberType*, *Name*, *Value*, and *SecondValue*.
If you include the parameter names, the parameters can appear in any order.

You can use the $this automatic variable in script blocks that define the values of new properties and methods.
You can use the $this automatic variable in script blocks that define the values of new properties and methods.
The $this variable refers to the instance of the object to which the properties and methods are being added.
For more information about the $this variable, see about_Automatic_Variables.

*

## RELATED LINKS

[Export-Clixml](Export-Clixml.md)
Expand Down