Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Compare two array

Reply
 
Old 03-12-2007   #1 (permalink)
Did


 
 

Compare two array

Hi all,
I have two identical arrays.
$a = 0,1,2,3
$b = 0,1,2,3

I need to know if the arrays is identical

if ($a -eq $b) this is doesn't working

Thanks,
Didi


My System SpecsSystem Spec
Old 03-12-2007   #2 (permalink)
Brandon Shell


 
 

Re: Compare two array

I believe you can use compare-object.

"Did" <didi10000@walla.co.il> wrote in message
news:1173698692.087060.208650@64g2000cwx.googlegroups.com...
> Hi all,
> I have two identical arrays.
> $a = 0,1,2,3
> $b = 0,1,2,3
>
> I need to know if the arrays is identical
>
> if ($a -eq $b) this is doesn't working
>
> Thanks,
> Didi
>


My System SpecsSystem Spec
Old 03-12-2007   #3 (permalink)
ktmd


 
 

Re: Compare two array

I have used compare-object successfully.$a = 1,2,3
$b = 1,3,4
$c = compare-object $a $b
$c
write-host "Objects inly exist in the first file"
$c | % { if ($_.SideIndicator -match '<=') {$_.InputObject}}

write-host "Objects inly exist in the second file"
$c | % { if ($_.SideIndicator -match '=>') {$_.InputObject}}


$a = "a","b","c"
$b = "a","c","d","e"
$d = compare-object $a $b
$d

write-host "Objects only exist in the first file"
$d | % { if ($_.SideIndicator -match '<=') {$_.InputObject}}

write-host "Objects only exist in the second file"
$d | % { if ($_.SideIndicator -match '=>') {$_.InputObject}}

regards,
ktmd




"Brandon Shell" wrote:

> I believe you can use compare-object.
>
> "Did" <didi10000@walla.co.il> wrote in message
> news:1173698692.087060.208650@64g2000cwx.googlegroups.com...
> > Hi all,
> > I have two identical arrays.
> > $a = 0,1,2,3
> > $b = 0,1,2,3
> >
> > I need to know if the arrays is identical
> >
> > if ($a -eq $b) this is doesn't working
> >
> > Thanks,
> > Didi
> >

>
>

My System SpecsSystem Spec
Old 03-12-2007   #4 (permalink)
ktmd


 
 

Re: Compare two array

FYI, when two arrays are the same, compare-object returns null.
ktmd

"ktmd" wrote:

> I have used compare-object successfully.$a = 1,2,3
> $b = 1,3,4
> $c = compare-object $a $b
> $c
> write-host "Objects inly exist in the first file"
> $c | % { if ($_.SideIndicator -match '<=') {$_.InputObject}}
>
> write-host "Objects inly exist in the second file"
> $c | % { if ($_.SideIndicator -match '=>') {$_.InputObject}}
>
>
> $a = "a","b","c"
> $b = "a","c","d","e"
> $d = compare-object $a $b
> $d
>
> write-host "Objects only exist in the first file"
> $d | % { if ($_.SideIndicator -match '<=') {$_.InputObject}}
>
> write-host "Objects only exist in the second file"
> $d | % { if ($_.SideIndicator -match '=>') {$_.InputObject}}
>
> regards,
> ktmd
>
>
>
>
> "Brandon Shell" wrote:
>
> > I believe you can use compare-object.
> >
> > "Did" <didi10000@walla.co.il> wrote in message
> > news:1173698692.087060.208650@64g2000cwx.googlegroups.com...
> > > Hi all,
> > > I have two identical arrays.
> > > $a = 0,1,2,3
> > > $b = 0,1,2,3
> > >
> > > I need to know if the arrays is identical
> > >
> > > if ($a -eq $b) this is doesn't working
> > >
> > > Thanks,
> > > Didi
> > >

> >
> >

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
How to create array without quotes? $array = (a,b,c) PowerShell
Array indexing: Want to say "Item #2 through the rest of the array." PowerShell
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46