Home:ALL Converter>Passing Psobject Property values to another Psobject

Passing Psobject Property values to another Psobject

Ask Time:2014-09-19T10:06:30         Author:user2821260

Json Formatter

I am using two PSObjects lets call them $job1 and $job2 that contain some identical Property Names. The properties for $job1 has the values but the matching properties for $job2 does not.I need to be able to do a foreach loop where if property name in $job1 matches $job2 property name, update Property value of $job2 based on the Property Name.

I was playing around with the below code but I cannot get it to update the Property values of $job2.

$job1.PSObject.Properties | %{if($_.Name -in $job2.PSObject.Properties.Name){[$_.Value = $job2.PSObject.Properties.Value}}

Thanks in advance for all the help!!

Author:user2821260,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25925263/passing-psobject-property-values-to-another-psobject
yy