# Compare Scripts not working with write-host

**URL:** <https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670>\
**Category:** PowerShell Help\
**Created:** [May 27, 2021, 6:36pm UTC](https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670 "2021-05-27T18:36:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunny123](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sunny123](https://forums.powershell.org/u/sunny123)\
**Post date:** [May 27, 2021, 6:36pm UTC](https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670/1 "2021-05-27T18:36:33Z")

</div>

Hi  
I have the following script off compare-object that is sending the results to outfile process7.txt.  
This is working fine.

```auto
type or foreach ($File in $FileList) {

    $FilePath1 = $File -replace 'Version1', $VersionList[0]

    $FilePath2 = $File -replace 'Version1', $VersionList[1]

    $FilePath3 = Get-ChildItem -Path $FilePath2

    $Content1 = Get-Content -Path $FilePath1

    $Content2 = Get-Content -Path $FilePath3

    $output = Compare-Object -ReferenceObject $Content1 -DifferenceObject $Content2

    write-output "File name is" $File "and it corresponding output is:" $output|Out-File -FilePath .\Process7.txt -Append

}paste code here

```

But the same script instead off sending to output file i want to write it out to a screen as follows:

```auto
foreach ($File in $FileList) {

    $FilePath1 = $File -replace 'Version1', $VersionList[0]

    $FilePath2 = $File -replace 'Version1', $VersionList[1]

    $FilePath3 = Get-ChildItem -Path $FilePath2

    $Content1 = Get-Content -Path $FilePath1

    $Content2 = Get-Content -Path $FilePath3

    $output = Compare-Object -ReferenceObject $Content1 -DifferenceObject $Content2|

    if($output.count -ne 0)

    {

     write-host "Files not equal"

    }

    else{

     Write-host "EQUAL!!"

}

```

But the script is hosed at the

prompt

> >

Please see attached.  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/c/c45d5c53161ac4aa3e213e26dd09c518e11eaac8.png)

What am i doing wrong?

Again thanks for the help in advance!

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [May 27, 2021, 8:02pm UTC](https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670/2 "2021-05-27T20:02:36Z")

</div>

You’re missing a curly brace at the end and have an extra pipe at the end of your compare-object line

---

<div class="post-metadata">

**Author:** ![sunny123](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sunny123](https://forums.powershell.org/u/sunny123)\
**Post date:** [May 27, 2021, 9:27pm UTC](https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670/3 "2021-05-27T21:27:54Z")

</div>

Thanks krzydoug…silly mistake. Appreciate your input.

Sunny

---

<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:24pm UTC](https://forums.powershell.org/t/compare-scripts-not-working-with-write-host/16670/4 "2024-05-16T20:24:28Z")

</div>

Closed on May 16, 2024, 8:24pm UTC


