# Displaying output of compare-object in textbox

**URL:** <https://forums.powershell.org/t/displaying-output-of-compare-object-in-textbox/882>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/displaying-output-of-compare-object-in-textbox/882 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/displaying-output-of-compare-object-in-textbox/882/1 "2011-12-31T18:30:00Z")

</div>

by Davehal at 2013-04-21 06:09:12

> Hi,  
>   
> I am new to powershell and am trying to do a simple (I thought :-P) comparison between the contents of two text files and display them in an output textbox.  
>   
> I have two textboxes called Diff1 and Diff2, these contain the paths to the files i want to compare. I then click a button called compare. I want to display the result in a textbox called console:  
>   
> code[$Compare\_OnClick=   
> {  
> #TODO: Place custom script here  
> $comp1 = Get-ChildItem -Recurse -Path $Diff1.text;  
> Write-Host "comp1 = " $comp1;  
> $console.AppendText("comp1 = " + $comp1);  
> $console.AppendText("`r`n");  
>   
> $comp2 = Get-ChildItem -Recurse -Path $Diff2.text;  
> Write-Host "comp2 = " $comp2;  
> $console.AppendText("comp2 = " + $comp2);  
> $console.AppendText("`r`n");  
>   
> $compOutput = Compare-Object $(Get-Content $comp1) $(Get-Content $comp2)  
>   
> Write-Host $compOutput;  
> $console.AppendText((Compare-Object $(Get-Content $comp1) $(Get-Content $comp2)));  
> $console.AppendText("`r`n");  
> }]  
>   
> The powershell console (output of Write-Host) displays everything correctly  
> I can see the two paths in the textbox no problem, but the result of the comparison ($compOutput) is not shown in the textbox.  
>   
> Does anyone know what I’m doing wrong? Or have any advice? I can’t figure out why I can display some things but the output of Compare-Object!!!  
>   
> Thanks in advance  
>   
> Dave

by MasterOfTheHat at 2013-04-22 07:00:59

> I’m guessing that $console is your text box. Do you see the "comp1 = comp1" and "comp2 = comp2" lines in the text box? And is there any reason you are running the Compare-Object command twice?

by Davehal at 2013-04-22 07:49:49

> Hi,  
>   
> Thanks for your reply,  
>   
> Yes, $console is my textbox, its just a large textbox on the qui.  
> I can see the output of comp1 = comp1 and comp2 = comp2 in this textbox.  
> I was editing the code when trying to track down the issue, that’s why the Compare-Object command is there twice, I forgot to correct it!  
>   
> I’ve pasted in a correct version of my code:  
>   
> $Compare\_OnClick=   
> {  
>   
> $comp1 = Get-ChildItem -Recurse -Path $Diff1.text;  
> Write-Host "comp1 = " $comp1;  
> $console.AppendText("comp1 = " + $comp1);  
> $console.AppendText("`r`n");  
>   
> $comp2 = Get-ChildItem -Recurse -Path $Diff2.text;  
> Write-Host "comp2 = " $comp2;  
> $console.AppendText("comp2 = " + $comp2);  
> $console.AppendText("`r`n");  
>   
> $compOutput = Compare-Object $(Get-Content $comp1) $(Get-Content $comp2);  
>   
> Write-Host $compOutput;  
> $console.AppendText($compOutput);  
> $console.AppendText("`r`n");  
> }  
>   
> Thanks!!!

by MasterOfTheHat at 2013-04-22 08:18:47

> Np! Btw, try using the Code or powershell tags to make the posts more readable…  
>   
> And check out the help for Compare-Object, (help compare-object -full):  
> `OUTPUTS None, or the objects that are different When you use the PassThru parameter, Compare-Object returns the objects that differed. Otherwise, this cmdlet does not generate any output.`  
>   
> So try adding -PassThru to the end of your Compare-Object command.

by Davehal at 2013-04-22 08:32:44

> Thanks very much, that worked - I’ll try RTFM in future 🙂  
>   
> `$compOutput = Compare-Object $(Get-Content $comp1) $(Get-Content $comp2) -PassThru;	$console.AppendText($compOutput);	`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:58pm UTC](https://forums.powershell.org/t/displaying-output-of-compare-object-in-textbox/882/2 "2024-05-16T20:58:35Z")

</div>


