Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Compare two array

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-12-2007   #1 (permalink)
Did
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare paths RickB PowerShell 4 04-30-2008 07:16 AM
compare users in csv to AD Niro PowerShell 2 12-26-2007 01:09 PM
how to compare in this situation IT Staff PowerShell 10 07-22-2007 08:32 AM
how to assign values to array and how to create array via variable Frank PowerShell 1 03-13-2007 05:18 PM
How can I compare two DVDs? Chris Vista General 1 09-26-2006 05:16 AM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com 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 2005-2008
Page generated in 0.25615 seconds with 10 queries