powershell - Compare-Object: PassThru parameter alters input variable -


easiest explain issue code snippet...

clear-host  $refobj = new-object system.object $refobj | add-member -membertype noteproperty -name objectmember1 -value 123  $diffobj = new-object system.object $diffobj | add-member -membertype noteproperty -name objectmember1 -value 456   write-output 'before 1st comparison...' $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select *   $x = compare-object -referenceobject $refobj -differenceobject $diffobj -includeequal  write-output 'after 1st comparison...' $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select *   $y = compare-object -referenceobject $refobj -differenceobject $diffobj -passthru -includeequal  write-output 'after 2nd comparison...' $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select * 

... , results (appears same in ps versions 3 , 5, haven't tested others) ...

query results

what i'm struggling understand why inclusion of -passthru parameter altering 1 of input variables, adding on additional parameter.

in addition struggling understand why happening, i'd avoid it. there way of specifying output variable compare-object cmdlet without altering input variables?

thanks in advance.

edit: it's clear me question wasn't clear enough. make more straightforward....

$y = compare-object -referenceobject $refobj -differenceobject $diffobj -passthru -includeequal 

with above, how stop sideindicator being added $refobj, , add $y instead? there doesn't seem -outvariable option compare-object, there way can this?

edit 2: turns out there -outvariable option compare-object, doesn't seem work...

compare-object -referenceobject $refobj -differenceobject $diffobj -includeequal -passthru -outvariable $objcomparisonresults 

i expect data in $objcomparisonresults, no data saved in variable.

compare-object adds sideindicator noteproperty. have @ objects produced. powershell produces object, not flat text parsed. using -passthru caused appear in console output.

clear-host $logfile = 'c:\src\t\pt.txt' if (test-path -path $logfile) { remove-item -path $logfile }  $refobj = new-object system.object $refobj | add-member -membertype noteproperty -name objectmember1 -value 123  $diffobj = new-object system.object $diffobj | add-member -membertype noteproperty -name objectmember1 -value 456   'before 1st comparison...' | out-file -filepath $logfile -append -encoding ascii  $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select * | gm |     out-file -filepath $logfile -append -encoding ascii   $x = compare-object -referenceobject $refobj -differenceobject $diffobj -includeequal | gm |     out-file -filepath $logfile -append -encoding ascii  'after 1st comparison...' | out-file -filepath $logfile -append -encoding ascii  $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select * | gm |     out-file -filepath $logfile -append -encoding ascii   $y = compare-object -referenceobject $refobj -differenceobject $diffobj -passthru -includeequal | gm |     out-file -filepath $logfile -append -encoding ascii  'after 2nd comparison...' | out-file -filepath $logfile -append -encoding ascii  $refobj | get-member | ? { $_.membertype  -eq 'noteproperty' } | select * | gm |     out-file -filepath $logfile -append -encoding ascii 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -