Redirecting the output

Hello everybody,
To search why at certain moments my machine does not go to sleep, I recorded the list of processes in two files, Process2023-11-06ù1.txt and Process2023-11-06ù2.txt

The display in there is multi-column, so to compare them I want to extract the names.

foreach($line in Get-Content Process2023-11-06ù1.txt){if($line.Length -gt 50){$line.Substring(58,40);}}

OK that writes me the names.
Now I need them in files, to compare them.
foreach($line in Get-Content Process2023-11-06ù1.txt){if($line.Length -gt 50){$line.Substring(58,40);}} | Out-File "test.txt"
That is much less efficient: I am said I have an empty pipe element, so nothing in the output file.
Perhaps did I miss anything?

You should use CSV files instead of plain text files. :point_up:t3:

If you want to compare objects in PowerShell you should use

What’s the actual question? What do you actually want to do?

I did things in a certain order: I first told what I actually wanted to do, and then I told how I attempted it.
Well it seems Compare-Object is a good idea.
Going to try that in a few hours, thanks.

Hello,
Well, it has rather been a few weeks, sorry.
Compare-Object aims to compare objects, OK, but a little more precision seems to be useful.
To begin with, each process has numbers (memory, file …) that vary, and this part seems somewhat too heavy to compare.
So, I decided to detect processes that appear or disappear.

I saw nothing in the options of Compare-Object to restrict the comparison to columns, is there?

I extract the names like this:

foreach($f in (Get-Content Process2023-11-06ù1.txt))
{if($f.ToString().Length -ge 58)
 {$f.ToString().Substring(58) >> Liste1.txt}}

(and then the same after replacing 1 by 2 at the end of the file names).

Maybe there is still something I did not understand in the syntax of Compare-Object

PS C:\Users\User> Compare-Object Liste1.txt Liste2.txt

InputObject SideIndicator
----------- -------------
Liste2.txt  =>
Liste1.txt  <=

We are OK about what to compare, but the results of the comparison would have been more useful.

So I had a look in WinMerge. Maybe the update of Edge is part of the problem, maybe audiodg, but this is another topic.

Really? How about -Property? :man_shrugging:t3:

Again … you should use CSV files instead of plain text. That would make your task way easier. :man_shrugging:t3:

The general approach would be something like this:

$ProcessList_01 = Get-Process
explorer.exe
notepad.exe
$ProcessList_02 = Get-Process
Compare-Object -ReferenceObject $ProcessList_01 -DifferenceObject $ProcessList_02 -Property Name 

What’s producing an output like this:

Name     SideIndicator
----     -------------
explorer =>
notepad  =>

Oh yes it is coherent, I presume with CSV you can affect a property name to each column.
Of course, with an example of three weeks ago, I take it “as is”, but a further test can be done with CSV.

You know what? I arrived just in time to know what the topic was, and now the last Windows update solves the problem: the keyboard backlight is shut down in the same time as the screen. So, probably I was not alone to notice that problem.
The disk keeps on working, but that is to update the applications.
Because of this it is not easy at all to test on this machine an application that has to do something when the machine comes out of sleep. But that … is another topic.