![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Compare-object doesn't seem to work with Arrays I think I'm doing this right... Any ideas? PS C:\Toolbox\Scripts\DNSCheck> $t TLD5.ULTRADNS.INFO TLD6.ULTRADNS.CO.UK TLD1.ULTRADNS.NET TLD2.ULTRADNS.NET TLD3.ULTRADNS.org TLD4.ULTRADNS.org PS C:\Toolbox\Scripts\DNSCheck> $v TLD4.ULTRADNS.org TLD5.ULTRADNS.INFO TLD6.ULTRADNS.CO.UK TLD1.ULTRADNS.NET TLD2.ULTRADNS.NET TLD3.ULTRADNS.org PS C:\Toolbox\Scripts\DNSCheck> compare-object -ref $t -diff $v Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null. At line:1 char:20 + compare-object -ref <<<< $t -diff $v PS C:\Toolbox\Scripts\DNSCheck> |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Compare-object doesn't seem to work with Arrays Actually - after doing some testing it looks like there is a problem with the way I created my arrays (they don't appear to be arrays). Here is the behavior I expected to see: PS C:\Toolbox\Scripts\DNSCheck> $a = @(1,2,3,4) PS C:\Toolbox\Scripts\DNSCheck> $b = @(1,4) PS C:\Toolbox\Scripts\DNSCheck> compare-object $a $b InputObject SideIndicator ----------- ------------- 2 <= 3 <= Now I just need to figure out what's wrong with my arrays... -Chris "Chris Harris" wrote: > I think I'm doing this right... Any ideas? > > PS C:\Toolbox\Scripts\DNSCheck> $t > TLD5.ULTRADNS.INFO > TLD6.ULTRADNS.CO.UK > TLD1.ULTRADNS.NET > TLD2.ULTRADNS.NET > TLD3.ULTRADNS.org > TLD4.ULTRADNS.org > PS C:\Toolbox\Scripts\DNSCheck> $v > TLD4.ULTRADNS.org > TLD5.ULTRADNS.INFO > TLD6.ULTRADNS.CO.UK > TLD1.ULTRADNS.NET > TLD2.ULTRADNS.NET > TLD3.ULTRADNS.org > PS C:\Toolbox\Scripts\DNSCheck> compare-object -ref $t -diff $v > Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because > it is null. > At line:1 char:20 > + compare-object -ref <<<< $t -diff $v > PS C:\Toolbox\Scripts\DNSCheck> |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Compare-object doesn't seem to work with Arrays Chris Harris wrote: > Actually - after doing some testing it looks like there is a problem with the > way I created my arrays (they don't appear to be arrays). > > Here is the behavior I expected to see: > > PS C:\Toolbox\Scripts\DNSCheck> $a = @(1,2,3,4) > PS C:\Toolbox\Scripts\DNSCheck> $b = @(1,4) > PS C:\Toolbox\Scripts\DNSCheck> compare-object $a $b > > InputObject SideIndicator > ----------- ------------- > 2 <= > 3 <= > > Now I just need to figure out what's wrong with my arrays... Using the gettype method will allow you to see what kind of object it is. 15# $a=5 16# $a.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType 17# |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Compare-object doesn't seem to work with Arrays "Chris Harris" <ChrisHarris@discussions.microsoft.com> wrote in message news:571754BB-E59B-489E-9584-A20C36D98CF2@microsoft.com... > Actually - after doing some testing it looks like there is a problem with > the > way I created my arrays (they don't appear to be arrays). > > Here is the behavior I expected to see: > > PS C:\Toolbox\Scripts\DNSCheck> $a = @(1,2,3,4) > PS C:\Toolbox\Scripts\DNSCheck> $b = @(1,4) > PS C:\Toolbox\Scripts\DNSCheck> compare-object $a $b > > InputObject SideIndicator > ----------- ------------- > 2 <= > 3 <= > > Now I just need to figure out what's wrong with my arrays... What you are actually trying to reproduce is this: PS> $a=@(1,4) PS> $b=@(4,1) PS> compare-object $a $b PS> As you can see, compare-object does not capture differences such as similar values sorted differently in an array. So if you want to identify sort differences between $t and $v you will have to write your own comparison routine. That shouldn't be too difficult though. A very basic example to get you started: PS> for ($i=0;$i -lt [System.Math]::Max($t.length,$v.length);$i++) { >> if ($t[$i] -ne $v[$i]) {"$i : $($t[$i]) <> $($v[$i])"} >> } >> 0 : TLD5.ULTRADNS.INFO <> TLD4.ULTRADNS.org 1 : TLD6.ULTRADNS.CO.UK <> TLD5.ULTRADNS.INFO 2 : TLD1.ULTRADNS.NET <> TLD6.ULTRADNS.CO.UK 3 : TLD2.ULTRADNS.NET <> TLD1.ULTRADNS.NET 4 : TLD3.ULTRADNS.org <> TLD2.ULTRADNS.NET 5 : TLD4.ULTRADNS.org <> TLD3.ULTRADNS.org Hope that helps, Jacques |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Compare-object doesn't seem to work with Arrays Hi Jacques - thanks for the reply. I'm not concerned about the sorting issues because I'm sorting the arrays before comparing them. What I'm concerned about is one array having more/less/different entries than the other. Here I have a hashtable where the values are arrays. Name Value ---- ----- ns2.microsage.net {bbns.blackbaud.com, bbns2.blackbaud.com} ns1.microsage.net On a side note, does anyone know what's going on in the example below? PS C:\Toolbox\Scripts\DNSCheck> $a = @("ns1.microsage.net", "ns2.microsage.net") PS C:\Toolbox\Scripts\DNSCheck> $b = @("ns1.microsage.net") PS C:\Toolbox\Scripts\DNSCheck> $a -eq $b ns1.microsage.net PS C:\Toolbox\Scripts\DNSCheck> $a -ne $b ns2.microsage.net PS C:\Toolbox\Scripts\DNSCheck> PS C:\Toolbox\Scripts\DNSCheck> $b = $a PS C:\Toolbox\Scripts\DNSCheck> $a ns1.microsage.net ns2.microsage.net PS C:\Toolbox\Scripts\DNSCheck> $b ns1.microsage.net ns2.microsage.net PS C:\Toolbox\Scripts\DNSCheck> $a -eq $b PS C:\Toolbox\Scripts\DNSCheck> $a -ne $b ns1.microsage.net ns2.microsage.net Thanks, Chris "Jacques Barathon [MS]" wrote: > "Chris Harris" <ChrisHarris@discussions.microsoft.com> wrote in message > news:571754BB-E59B-489E-9584-A20C36D98CF2@microsoft.com... > > Actually - after doing some testing it looks like there is a problem with > > the > > way I created my arrays (they don't appear to be arrays). > > > > Here is the behavior I expected to see: > > > > PS C:\Toolbox\Scripts\DNSCheck> $a = @(1,2,3,4) > > PS C:\Toolbox\Scripts\DNSCheck> $b = @(1,4) > > PS C:\Toolbox\Scripts\DNSCheck> compare-object $a $b > > > > InputObject SideIndicator > > ----------- ------------- > > 2 <= > > 3 <= > > > > Now I just need to figure out what's wrong with my arrays... > > What you are actually trying to reproduce is this: > > PS> $a=@(1,4) > PS> $b=@(4,1) > PS> compare-object $a $b > PS> > > As you can see, compare-object does not capture differences such as similar > values sorted differently in an array. So if you want to identify sort > differences between $t and $v you will have to write your own comparison > routine. That shouldn't be too difficult though. A very basic example to get > you started: > > PS> for ($i=0;$i -lt [System.Math]::Max($t.length,$v.length);$i++) { > >> if ($t[$i] -ne $v[$i]) {"$i : $($t[$i]) <> $($v[$i])"} > >> } > >> > 0 : TLD5.ULTRADNS.INFO <> TLD4.ULTRADNS.org > 1 : TLD6.ULTRADNS.CO.UK <> TLD5.ULTRADNS.INFO > 2 : TLD1.ULTRADNS.NET <> TLD6.ULTRADNS.CO.UK > 3 : TLD2.ULTRADNS.NET <> TLD1.ULTRADNS.NET > 4 : TLD3.ULTRADNS.org <> TLD2.ULTRADNS.NET > 5 : TLD4.ULTRADNS.org <> TLD3.ULTRADNS.org > > Hope that helps, > Jacques > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| compare-object | PowerShell | |||
| compare object | PowerShell | |||
| Compare-Object and Get the name of object/File? | PowerShell | |||
| Testing object arrays using Compare-Object and -contains | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||