Skip to content
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

Remove example #5, renumbered. #8846

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
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
24 changes: 1 addition & 23 deletions reference/5.1/Microsoft.PowerShell.Utility/Add-Member.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,7 @@ $A.SizeInMB()
0.43
```

### Example 5: Copy all properties of an object to another

This function copies all of the properties of one object to another object.

The `foreach` loop uses the `Get-Member` cmdlet to get each of the properties of the **From**
object. The commands within the `foreach` loop are performed in series on each of the properties.

The `Add-Member` command adds the property of the **From** object to the **To** object as a
**NoteProperty**. The value is copied using the **Value** parameter. It uses the **Force** parameter
to add members with the same member name.

```powershell
function Copy-Property ($From, $To)
{
$properties = Get-Member -InputObject $From -MemberType Property
foreach ($p in $properties)
{
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
}
}
```

### Example 6: Create a custom object
### Example 5: Create a custom object

This example creates an **Asset** custom object.

Expand Down
24 changes: 1 addition & 23 deletions reference/7.0/Microsoft.PowerShell.Utility/Add-Member.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,7 @@ $A.SizeInMB()
0.43
```

### Example 5: Copy all properties of an object to another

This function copies all of the properties of one object to another object.

The `foreach` loop uses the `Get-Member` cmdlet to get each of the properties of the **From**
object. The commands within the `foreach` loop are performed in series on each of the properties.

The `Add-Member` command adds the property of the **From** object to the **To** object as a
**NoteProperty**. The value is copied using the **Value** parameter. It uses the **Force** parameter
to add members with the same member name.

```powershell
function Copy-Property ($From, $To)
{
$properties = Get-Member -InputObject $From -MemberType Property
foreach ($p in $properties)
{
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
}
}
```

### Example 6: Create a custom object
### Example 5: Create a custom object

This example creates an **Asset** custom object.

Expand Down
24 changes: 1 addition & 23 deletions reference/7.2/Microsoft.PowerShell.Utility/Add-Member.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,7 @@ $A.SizeInMB()
0.43
```

### Example 5: Copy all properties of an object to another

This function copies all of the properties of one object to another object.

The `foreach` loop uses the `Get-Member` cmdlet to get each of the properties of the **From**
object. The commands within the `foreach` loop are performed in series on each of the properties.

The `Add-Member` command adds the property of the **From** object to the **To** object as a
**NoteProperty**. The value is copied using the **Value** parameter. It uses the **Force** parameter
to add members with the same member name.

```powershell
function Copy-Property ($From, $To)
{
$properties = Get-Member -InputObject $From -MemberType Property
foreach ($p in $properties)
{
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
}
}
```

### Example 6: Create a custom object
### Example 5: Create a custom object

This example creates an **Asset** custom object.

Expand Down
24 changes: 1 addition & 23 deletions reference/7.3/Microsoft.PowerShell.Utility/Add-Member.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,7 @@ $A.SizeInMB()
0.43
```

### Example 5: Copy all properties of an object to another

This function copies all of the properties of one object to another object.

The `foreach` loop uses the `Get-Member` cmdlet to get each of the properties of the **From**
object. The commands within the `foreach` loop are performed in series on each of the properties.

The `Add-Member` command adds the property of the **From** object to the **To** object as a
**NoteProperty**. The value is copied using the **Value** parameter. It uses the **Force** parameter
to add members with the same member name.

```powershell
function Copy-Property ($From, $To)
{
$properties = Get-Member -InputObject $From -MemberType Property
foreach ($p in $properties)
{
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
}
}
```

### Example 6: Create a custom object
### Example 5: Create a custom object

This example creates an **Asset** custom object.

Expand Down