Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created November 28, 2018 18:02
Show Gist options
  • Select an option

  • Save nohwnd/b32e7bdfdf5a05525df812aab07a4afc to your computer and use it in GitHub Desktop.

Select an option

Save nohwnd/b32e7bdfdf5a05525df812aab07a4afc to your computer and use it in GitHub Desktop.
replace properties on psobject
$MyObject = [PSCustomObject]@{ Value = 15; Value2 = 13; Value3 = "j" }
$Fields = @{
Value = "special"
Value2 = "Different"
}
$hashtable = @{}
foreach ($property in $MyObject.PSObject.Properties) {
if ($Fields.ContainsKey($property.Name))
{
$hashtable[$Fields[$property.name]] = $property.Value
}
else
{
$hashtable[$property.Name] = $property.Value
}
}
[PsCustomObject]$hashtable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment