powershell - Compare the properties of two PsCustomObjects -
i know can compare values of 2 powershell objects:
ps> $a = [pscustomobject]@{"a"=1; "b"=$true; "c"=$false} ps> $b = [pscustomobject]@{"a"=1; "b"=$false; "c"=$false} ps> compare-object $a $b -property a, b, c b c sideindicator - - - ------------- 1 false false => 1 true false <= however, need compare existance properties of 2 powershell objects.
these objects considered same:
ps> $a = [pscustomobject]@{"a"=1; "b"=$true; "c"=$false} ps> $b = [pscustomobject]@{"a"=1; "b"=$false; "c"=$true} ps> compare-foo $a $b true these objects considered not same:
ps> $a = [pscustomobject]@{"a"=1; "c"=$false} ps> $b = [pscustomobject]@{"a"=1; "b"=$false; "c"=$false} ps> compare-foo $a $b false is there way this?
i can think of few ways this, straightforward not tested:
$a.keys | foreach-object { $c = $b["$_"]; if ($c -eq "") {return $false;} }
Comments
Post a Comment