Last active
February 24, 2020 05:38
-
-
Save tackme31/ef7e1a961eae6c8732a5d0006b14bbb0 to your computer and use it in GitHub Desktop.
Rename a property name of an object in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$obj = [PSCustomObject]@{ | |
Foo = "foo value" | |
Bar = "bar value" | |
Baz = "baz value" | |
} | |
$hogeProp = @{ | |
Name = "Hoge" | |
Expression = { | |
return $_.Foo | |
} | |
} | |
$newObj = $obj | select *,hogeProp -ExcludeProperty Foo | |
# or select *,@{N="Hoge";E={$_.Foo}} -ExcludeProperty Foo | |
Write-Output $newObj | |
# Bar Baz Hoge | |
# --- --- ---- | |
# bar value baz value foo value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment