user3914798 user3914798 - 7 months ago 32
PowerShell Question

compare-object doesn't give any output

i run

$serv1=gwmi -Namespace Root\cimv2 -Class Win32_service

i stop some services manually and then run

$serv2=gwmi -Namespace Root\cimv2 -Class Win32_service

and then i compare these 2 objects

compare-object $serv1 $serv2

compare-object -referenceobject $serv1 -differenceobject $serv2

both doesn't return any difference however both have some values different


Compare-Object compares the Path property of each wmi instance object in the input collections - they will be the same no matter whether the service is running or not.

Use the -Property parameter to compare on specific properties, ie.

Compare-Object $serv1 $serv2 -Property Name,State