Compare Object Powershell





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I want to compare two objects and get only the different values. I have this code:



$a = ("this is blah blah DOG")
$b = ("Dit is blah BLAH dog")
Compare-Object -ReferenceObject $a -DifferenceObject $b


with the above code I get the following output:



InputObject           SideIndicator
----------- -------------
Dit is blah BLAH dog =>
this is blah blah DOG <=


However I want only the different values in both the objects i.e. Dit and this










share|improve this question































    0















    I want to compare two objects and get only the different values. I have this code:



    $a = ("this is blah blah DOG")
    $b = ("Dit is blah BLAH dog")
    Compare-Object -ReferenceObject $a -DifferenceObject $b


    with the above code I get the following output:



    InputObject           SideIndicator
    ----------- -------------
    Dit is blah BLAH dog =>
    this is blah blah DOG <=


    However I want only the different values in both the objects i.e. Dit and this










    share|improve this question



























      0












      0








      0








      I want to compare two objects and get only the different values. I have this code:



      $a = ("this is blah blah DOG")
      $b = ("Dit is blah BLAH dog")
      Compare-Object -ReferenceObject $a -DifferenceObject $b


      with the above code I get the following output:



      InputObject           SideIndicator
      ----------- -------------
      Dit is blah BLAH dog =>
      this is blah blah DOG <=


      However I want only the different values in both the objects i.e. Dit and this










      share|improve this question
















      I want to compare two objects and get only the different values. I have this code:



      $a = ("this is blah blah DOG")
      $b = ("Dit is blah BLAH dog")
      Compare-Object -ReferenceObject $a -DifferenceObject $b


      with the above code I get the following output:



      InputObject           SideIndicator
      ----------- -------------
      Dit is blah BLAH dog =>
      this is blah blah DOG <=


      However I want only the different values in both the objects i.e. Dit and this







      powershell compareobject






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 16:07









      Matt

      34.4k74271




      34.4k74271










      asked Nov 23 '18 at 15:56









      wrdwwrdw

      286




      286
























          3 Answers
          3






          active

          oldest

          votes


















          3














          Compare-Object works on the whole objects and its properties. It will not do lazy string matching. If you wanted that you need to split the string into arrays first



          $a = "this is blah blah DOG".Split()
          $b = "Dit is blah BLAH dog".Split()
          Compare-Object -ReferenceObject $a -DifferenceObject $b


          Beware of potential issues with case sensitivity and use the -CaseSensitive as needed.






          share|improve this answer





















          • 1





            Great SO minds think alike

            – No Refunds No Returns
            Nov 23 '18 at 16:12



















          2














          For this specific example:



          $a = ("this is blah blah DOG").Split(" ")
          $b = ("Dit is blah BLAH dog").Split(" ")
          Compare-Object -ReferenceObject $a -DifferenceObject $b





          share|improve this answer
























          • When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

            – wrdw
            Nov 23 '18 at 16:18






          • 1





            Recommend you post a minimum exact repro of what you are wanting to do.

            – No Refunds No Returns
            Nov 23 '18 at 16:38



















          0














          You don't show what your csv file looks like, so, there's that, but stepping though what you are after.



          ($a = Get-Content -Path 'D:Documentsfile1.txt')
          ($b = Get-Content -Path 'D:Documentsfile2.txt')
          Compare-Object -ReferenceObject $a -DifferenceObject $b

          <#
          What's in the two files

          file1
          hello
          world



          file2
          hello
          world



          InputObject SideIndicator
          ----------- -------------
          file2 =>
          file1 <=
          #>




          ($a = Get-Content -Path 'D:Documentsfile1.csv')
          ($b = Get-Content -Path 'D:Documentsfile2.csv')
          Compare-Object -ReferenceObject $a -DifferenceObject $b

          <#
          What's in the two files

          Col1,Col2,Col3
          file1,hello,world



          Col1,Col2,Col3
          file2,hello,world



          InputObject SideIndicator
          ----------- -------------
          file2,hello,world =>
          file1,hello,world <=
          #>



          ($a = (Get-Content -Path 'D:Documentsfile1.csv' | Select -Skip 1) -split ',')
          ($b = (Get-Content -Path 'D:Documentsfile2.csv' | Select -Skip 1) -split ',')
          Compare-Object -ReferenceObject $a -DifferenceObject $b

          <#
          file1
          hello
          world



          file2
          hello
          world




          InputObject SideIndicator
          ----------- -------------
          file2 =>
          file1 <=
          #>


          Lastly, this also sounds eerily like this Q&A



          Compare two lists in Powershell






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449683%2fcompare-object-powershell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            Compare-Object works on the whole objects and its properties. It will not do lazy string matching. If you wanted that you need to split the string into arrays first



            $a = "this is blah blah DOG".Split()
            $b = "Dit is blah BLAH dog".Split()
            Compare-Object -ReferenceObject $a -DifferenceObject $b


            Beware of potential issues with case sensitivity and use the -CaseSensitive as needed.






            share|improve this answer





















            • 1





              Great SO minds think alike

              – No Refunds No Returns
              Nov 23 '18 at 16:12
















            3














            Compare-Object works on the whole objects and its properties. It will not do lazy string matching. If you wanted that you need to split the string into arrays first



            $a = "this is blah blah DOG".Split()
            $b = "Dit is blah BLAH dog".Split()
            Compare-Object -ReferenceObject $a -DifferenceObject $b


            Beware of potential issues with case sensitivity and use the -CaseSensitive as needed.






            share|improve this answer





















            • 1





              Great SO minds think alike

              – No Refunds No Returns
              Nov 23 '18 at 16:12














            3












            3








            3







            Compare-Object works on the whole objects and its properties. It will not do lazy string matching. If you wanted that you need to split the string into arrays first



            $a = "this is blah blah DOG".Split()
            $b = "Dit is blah BLAH dog".Split()
            Compare-Object -ReferenceObject $a -DifferenceObject $b


            Beware of potential issues with case sensitivity and use the -CaseSensitive as needed.






            share|improve this answer















            Compare-Object works on the whole objects and its properties. It will not do lazy string matching. If you wanted that you need to split the string into arrays first



            $a = "this is blah blah DOG".Split()
            $b = "Dit is blah BLAH dog".Split()
            Compare-Object -ReferenceObject $a -DifferenceObject $b


            Beware of potential issues with case sensitivity and use the -CaseSensitive as needed.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 16:13

























            answered Nov 23 '18 at 16:09









            MattMatt

            34.4k74271




            34.4k74271








            • 1





              Great SO minds think alike

              – No Refunds No Returns
              Nov 23 '18 at 16:12














            • 1





              Great SO minds think alike

              – No Refunds No Returns
              Nov 23 '18 at 16:12








            1




            1





            Great SO minds think alike

            – No Refunds No Returns
            Nov 23 '18 at 16:12





            Great SO minds think alike

            – No Refunds No Returns
            Nov 23 '18 at 16:12













            2














            For this specific example:



            $a = ("this is blah blah DOG").Split(" ")
            $b = ("Dit is blah BLAH dog").Split(" ")
            Compare-Object -ReferenceObject $a -DifferenceObject $b





            share|improve this answer
























            • When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

              – wrdw
              Nov 23 '18 at 16:18






            • 1





              Recommend you post a minimum exact repro of what you are wanting to do.

              – No Refunds No Returns
              Nov 23 '18 at 16:38
















            2














            For this specific example:



            $a = ("this is blah blah DOG").Split(" ")
            $b = ("Dit is blah BLAH dog").Split(" ")
            Compare-Object -ReferenceObject $a -DifferenceObject $b





            share|improve this answer
























            • When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

              – wrdw
              Nov 23 '18 at 16:18






            • 1





              Recommend you post a minimum exact repro of what you are wanting to do.

              – No Refunds No Returns
              Nov 23 '18 at 16:38














            2












            2








            2







            For this specific example:



            $a = ("this is blah blah DOG").Split(" ")
            $b = ("Dit is blah BLAH dog").Split(" ")
            Compare-Object -ReferenceObject $a -DifferenceObject $b





            share|improve this answer













            For this specific example:



            $a = ("this is blah blah DOG").Split(" ")
            $b = ("Dit is blah BLAH dog").Split(" ")
            Compare-Object -ReferenceObject $a -DifferenceObject $b






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 16:10









            No Refunds No ReturnsNo Refunds No Returns

            5,61441936




            5,61441936













            • When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

              – wrdw
              Nov 23 '18 at 16:18






            • 1





              Recommend you post a minimum exact repro of what you are wanting to do.

              – No Refunds No Returns
              Nov 23 '18 at 16:38



















            • When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

              – wrdw
              Nov 23 '18 at 16:18






            • 1





              Recommend you post a minimum exact repro of what you are wanting to do.

              – No Refunds No Returns
              Nov 23 '18 at 16:38

















            When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

            – wrdw
            Nov 23 '18 at 16:18





            When I do the same for an object that imports values from a csv file I get items in both the objects. Whereas I only want items that are in object1 but not in object2

            – wrdw
            Nov 23 '18 at 16:18




            1




            1





            Recommend you post a minimum exact repro of what you are wanting to do.

            – No Refunds No Returns
            Nov 23 '18 at 16:38





            Recommend you post a minimum exact repro of what you are wanting to do.

            – No Refunds No Returns
            Nov 23 '18 at 16:38











            0














            You don't show what your csv file looks like, so, there's that, but stepping though what you are after.



            ($a = Get-Content -Path 'D:Documentsfile1.txt')
            ($b = Get-Content -Path 'D:Documentsfile2.txt')
            Compare-Object -ReferenceObject $a -DifferenceObject $b

            <#
            What's in the two files

            file1
            hello
            world



            file2
            hello
            world



            InputObject SideIndicator
            ----------- -------------
            file2 =>
            file1 <=
            #>




            ($a = Get-Content -Path 'D:Documentsfile1.csv')
            ($b = Get-Content -Path 'D:Documentsfile2.csv')
            Compare-Object -ReferenceObject $a -DifferenceObject $b

            <#
            What's in the two files

            Col1,Col2,Col3
            file1,hello,world



            Col1,Col2,Col3
            file2,hello,world



            InputObject SideIndicator
            ----------- -------------
            file2,hello,world =>
            file1,hello,world <=
            #>



            ($a = (Get-Content -Path 'D:Documentsfile1.csv' | Select -Skip 1) -split ',')
            ($b = (Get-Content -Path 'D:Documentsfile2.csv' | Select -Skip 1) -split ',')
            Compare-Object -ReferenceObject $a -DifferenceObject $b

            <#
            file1
            hello
            world



            file2
            hello
            world




            InputObject SideIndicator
            ----------- -------------
            file2 =>
            file1 <=
            #>


            Lastly, this also sounds eerily like this Q&A



            Compare two lists in Powershell






            share|improve this answer




























              0














              You don't show what your csv file looks like, so, there's that, but stepping though what you are after.



              ($a = Get-Content -Path 'D:Documentsfile1.txt')
              ($b = Get-Content -Path 'D:Documentsfile2.txt')
              Compare-Object -ReferenceObject $a -DifferenceObject $b

              <#
              What's in the two files

              file1
              hello
              world



              file2
              hello
              world



              InputObject SideIndicator
              ----------- -------------
              file2 =>
              file1 <=
              #>




              ($a = Get-Content -Path 'D:Documentsfile1.csv')
              ($b = Get-Content -Path 'D:Documentsfile2.csv')
              Compare-Object -ReferenceObject $a -DifferenceObject $b

              <#
              What's in the two files

              Col1,Col2,Col3
              file1,hello,world



              Col1,Col2,Col3
              file2,hello,world



              InputObject SideIndicator
              ----------- -------------
              file2,hello,world =>
              file1,hello,world <=
              #>



              ($a = (Get-Content -Path 'D:Documentsfile1.csv' | Select -Skip 1) -split ',')
              ($b = (Get-Content -Path 'D:Documentsfile2.csv' | Select -Skip 1) -split ',')
              Compare-Object -ReferenceObject $a -DifferenceObject $b

              <#
              file1
              hello
              world



              file2
              hello
              world




              InputObject SideIndicator
              ----------- -------------
              file2 =>
              file1 <=
              #>


              Lastly, this also sounds eerily like this Q&A



              Compare two lists in Powershell






              share|improve this answer


























                0












                0








                0







                You don't show what your csv file looks like, so, there's that, but stepping though what you are after.



                ($a = Get-Content -Path 'D:Documentsfile1.txt')
                ($b = Get-Content -Path 'D:Documentsfile2.txt')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                What's in the two files

                file1
                hello
                world



                file2
                hello
                world



                InputObject SideIndicator
                ----------- -------------
                file2 =>
                file1 <=
                #>




                ($a = Get-Content -Path 'D:Documentsfile1.csv')
                ($b = Get-Content -Path 'D:Documentsfile2.csv')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                What's in the two files

                Col1,Col2,Col3
                file1,hello,world



                Col1,Col2,Col3
                file2,hello,world



                InputObject SideIndicator
                ----------- -------------
                file2,hello,world =>
                file1,hello,world <=
                #>



                ($a = (Get-Content -Path 'D:Documentsfile1.csv' | Select -Skip 1) -split ',')
                ($b = (Get-Content -Path 'D:Documentsfile2.csv' | Select -Skip 1) -split ',')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                file1
                hello
                world



                file2
                hello
                world




                InputObject SideIndicator
                ----------- -------------
                file2 =>
                file1 <=
                #>


                Lastly, this also sounds eerily like this Q&A



                Compare two lists in Powershell






                share|improve this answer













                You don't show what your csv file looks like, so, there's that, but stepping though what you are after.



                ($a = Get-Content -Path 'D:Documentsfile1.txt')
                ($b = Get-Content -Path 'D:Documentsfile2.txt')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                What's in the two files

                file1
                hello
                world



                file2
                hello
                world



                InputObject SideIndicator
                ----------- -------------
                file2 =>
                file1 <=
                #>




                ($a = Get-Content -Path 'D:Documentsfile1.csv')
                ($b = Get-Content -Path 'D:Documentsfile2.csv')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                What's in the two files

                Col1,Col2,Col3
                file1,hello,world



                Col1,Col2,Col3
                file2,hello,world



                InputObject SideIndicator
                ----------- -------------
                file2,hello,world =>
                file1,hello,world <=
                #>



                ($a = (Get-Content -Path 'D:Documentsfile1.csv' | Select -Skip 1) -split ',')
                ($b = (Get-Content -Path 'D:Documentsfile2.csv' | Select -Skip 1) -split ',')
                Compare-Object -ReferenceObject $a -DifferenceObject $b

                <#
                file1
                hello
                world



                file2
                hello
                world




                InputObject SideIndicator
                ----------- -------------
                file2 =>
                file1 <=
                #>


                Lastly, this also sounds eerily like this Q&A



                Compare two lists in Powershell







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 1:52









                postanotepostanote

                4,1372411




                4,1372411






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449683%2fcompare-object-powershell%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]