Skip to content

the copy-property function in example 6 is incorrect #4220

@jszabo98

Description

@jszabo98

In the example, the add-member command is broken into two lines before -Value. And then the assignment statement "$To.$($p.Name) = $From.$($p.Name)" needs to be on its own line. But it doesn't seem to be needed anyway (or -force). Also, I added ",NoteProperty" to the foreach line, otherwise it usually comes up empty. This method doesn't add properties to strings. I don't know how get-content does it.

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

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-utilityArea - Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions