Powershell Custom Properties - Change Property name

With object properties "Name" is a read-only property, and so cannot be changed during runtime.

$objTest = New-Object -TypeName PSObject -Property @{ Foo = 42; Bar = 99 }
$objTest.PSObject.Properties["Foo"].Name  # Output: Foo.
$objTest.PSObject.Properties["Foo"].Name = "NotFoo"  # Output: 'Name' is a ReadOnly property.

An alternate to creating a new property and copying values may be to create a new "AliasProperty", which is a new property (with its own name) that is simply linked to an existing property.

eg.:

PS Y:\> $objTest | Add-Member -MemberType AliasProperty -Name Notfoo -Value Foo
PS Y:\> $objtest

Bar Foo Notfoo
--- --- ------
 99  42     42

PS Y:\> $objtest.Foo = 123
PS Y:\> $objtest

Bar Foo Notfoo
--- --- ------
 99 123    123