locked
compare-object simple script comparation wrong output RRS feed

  • Question

  • Dear all, just create a simple script to compare printers on 2 print servers and Im getting objects that exist on both servers as result, no idea way, please help, please chekc bellow the script and content:

    ### Compare printers
    $PrinterServer1= "server1"
    $PrinterServer2= "server2"


    $printersSRV1= Get-Printer -ComputerName  $PrinterServer1 | select name
    $printersSRV2= Get-Printer -ComputerName  $PrinterServer2 | select name

    Compare-Object $printersSRV1 $printersSRV2

    Wednesday, October 16, 2019 1:20 PM

Answers

  • You should be able compare two objects for equality of properties and values by using Compare-Object to compare the Properties properties of both objects. Example:


    if ( -not (Compare-Object $obj1.PSObject.Properties $obj2.PSObject.Properties) ) {
      "object properties and values match"
    }
    else {
      "object properties and values do not match"
    }
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Tuesday, April 14, 2020 4:55 PM
    Wednesday, October 16, 2019 4:13 PM