Skip to main content

Compare the Output of Two Commands

Problem

You want to compare the output of two commands.

Solution

To compare the output of two commands, store the output of each command in variables, and then use the CompareObject cmdlet to compare those variables:

PS >notepad PS >$processes = GetProcess PS >StopProcess ProcessName Notepad PS >$newProcesses = GetProcess PS >CompareObject $processes $newProcesses

InputObject SideIndicator

System.Diagnostics.Process (notepad) <=

Discussion

The solution shows how to determine which processes have exited between the two calls to GetProcess. The SideIndicator of <= tells us that the process was present in the left collection ($processes) but not in the right ($newProcesses).

For more information about the CompareObject cmdlet, type GetHelp CompareObject.

Compare and analyze PowerShell command outputs efficiently on a United Kingdom Dedicated Server, providing dedicated resources, reliable performance, and full administrative control for monitoring and managing server operations.

Help Category