Truncated Output to Screen and File

I’m using the Get-ChildItem to compare two folders containing mp4 files to to determine similarities and differences between them. In a quick test with output to the screen it worked perfectly when the mp4 files had short file names. However, when I ran it on the actual folders the listed input showed that longer file names were being truncated and the Sideindicator column was not displayed at all. Thinking this truncation had something to do with the output being too wide for the screen I output the screen details to a file, which is what I really need, but I ended up with the same result in the file as on the screen. I would, be grateful if anyone could tell me how to get the full screen output including the SideIndicator info into a file. Here is my coding (Dr Scripto)
’ $File1 = Get-ChildItem -Recurse -path C:\Music\mp4s’
’ $File2 = Get-ChildItem -Recurse -path C:\Music\mp4s\Annexe’
’ Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 > C:\Music\Mp4s’

Col,
Welcome to the forum. :wave:t3:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

That’s not completely wrong though. :wink:

If it’s just about the SideIndicator column you could simply change the order of the columns displayed by using Select-Object

Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 |
    Select-Object -Property SideIndicator, InputObject

Another option for the screen output would be to format the output as you like it with Format-Table for example:

Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 |
    Format-Table -AutoSize

If your console is wide enough it should show both columns.

For the output to a file I’d recommend to use Export-Csv instead of Out-File when the output contains at least 2 properties. This way no information gets truncated.

Compare-Object -ReferenceObject $File1 -DifferenceObject $File2 |
    Export-Csv -Path 'C:\Music\Mp4s.csv' -NoTypeInformation

And BTW: Please do not use aliasses in scripts or in forums like this as they make the code harder to read.
Thanks in advance.

@Olaf. Thank you for your quick response. Your last suggestion worked best for me with no truncation in the file. As you will know the coding currently shows any file unique to either File 1 (<=) or File2 (=>) but files common to both are not listed but are ignored. Is there anyway to use -IncludeEqual in the coding so that the output file also displays common files (==) as well as the Reference and Difference ones. As far as I can determine I can’t find anyway to include -IncludeEqual in the coding to achieve this but then I have just started with Powershell and have a lot to learn. I know I could just use -IncludeEqual as a separate run but it would be great if it could be combined in the coding. Anyway, I appreciate the assistance you have given me. Thank you very much.

By the way the alias (Dr Scripto) was not mine. I was just indicating that I had “appropriated” the coding from the Microsoft Scripting Guy’s site!

@Olaf. Just discovered that if I run the comparison just using -IncludeEqual it automatically displays the common files AND the differences - unless you deliberately exclude the differences in the parameter. I’ve sure got a lot to learn!

Great that you’ve found the solution yourself. :+1:t3:

Please, always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them.

In the vast majority of the cases you’re not the very first one with a given tasks. So there are pretty likely more than enough examples out there you could adapt to your particular needs and you could learn from. :wink:

@Olaf. Sadly I’m less smart than I thought I was! My “solution” has let me down. I must have got something in the parameters wrong as the output (although the formatting is just the way I want it) is nevertheless showing incorrect results. I get instances where the SideIndicator is showing == when an MP4 exists only in one file and other examples where the indication is <= when it should be =>. I would be grateful if you would take a look at my coding and see where it must be wrong. It’s a somewhat strange anomaly as a test using shorter mp4 names produced an all correct output. Here is my coding:

< $File1 = Get-ChildItem -Recurse -path C:\Mp4s
$File2 = Get-ChildItem -Recurse -path C:\Annexe
Compare-Object -ReferenceObject $File1 -DifferenceObject
$File2 -IncludeEqual |
Export-Csv -Path ‘C:\Mp4s\Mp4s.csv’ -NoTypeInformation/>

… again … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> )!!! Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Since Get-ChildItem outputs objects with properties you should specify what properties you want to use to compare. I’d expect you want to compare the Name.

$Var1 = Get-ChildItem -Path C:\Mp4s -Recurse
$Var2 = Get-ChildItem -Path C:\Annexe -Recurse
Compare-Object -ReferenceObject $Var1 -DifferenceObject $Var2 -Property 'Name' -IncludeEqual |
Export-Csv -Path 'C:\Mp4s\Mp4s.csv' -NoTypeInformation

@Olaf. Thank you for your continued support. Unfortunately, the SideIndicator is still not reporting accurate comparisons. For example, a file which is common to both folders is reported as being unique to only one. Perhaps, for comparison purposes, the number of characters deemed acceptable in a file name is limited. Whatever the reason, I have now given up on using Powershell and have started to look for an alternative solution. But thank you very much for your generous help.

No.

I’ve made a mistake in my last reply. I used the FullName property where I should have used the name property. I fixed my code suggestion above. Try again please.

@Olaf. I have checked the output and as far as I can determine, given the large number of files involved, it all seems to be working perfectly now. This has been a valuable learning point for me! Thank you very much for your support