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 - Comparison of two sets of Data

Reply
 
Old 05-11-2009   #1 (permalink)
Jobbsy


 
 

Comparison of two sets of Data

I believe this is going to involve arrays and would like some guidance

But basically I want to write a list of these that don't match after a
comparison of the two sets of data.

In the following format obviously when the outer foreach doesn't match the
nested foreach it writes a "notmatch" - even if there is a match within the
two sets of data.

$CSVFile = "D:\Clusters.csv"
$Directory = "D:\Clusters"
$clusterfiles = dir $Directory | get-childitem -name
$ICLUSTERS = Import-Csv $CSVFile

ForEach ($ICLUSTER in $ICLUSTERS){
$Cluster = $ICLUSTER.cluster


ForEach ($clusterfile in $clusterfiles){
$clusfile = $clusterfile.name
$clusfilename = $clusterfile.split(".")[0]

if ($Cluster -notmatch $clusfilename){
write-host $Cluster " not match"
}#if

}#foreach

}#foreach
--
jobbsy@xxxxxx

My System SpecsSystem Spec
Old 05-11-2009   #2 (permalink)
Adrian


 
 

Re: Comparison of two sets of Data

Check out compare-object. I have used this a few times recently, it's
really easy and flexible.

$previous = import-clixml "D:\LastResults.xml"
$current = dir "D:\directory"
compare-object $previous $current -Property name -IncludeEqual

$current | export-clixml "D:\LastResults.xml"


Drop the -IncludeEqual to just see the changes. You can swap out name
for size, or compare multiple properties. Very handy!


Adrian

On May 11, 12:51*pm, Jobbsy <Job...@xxxxxx> wrote:
Quote:

> I believe this is going to involve arrays and would like some guidance
>
> But basically I want to write a list of these that don't match after a
> comparison of the two sets of data.
>
> In the following format obviously when the outer foreach doesn't match the
> nested foreach it writes a "notmatch" - even if there is a match within the
> two sets of data.
>
> $CSVFile = "D:\Clusters.csv"
> $Directory = "D:\Clusters"
> $clusterfiles = dir $Directory | get-childitem -name
> $ICLUSTERS = Import-Csv $CSVFile
>
> ForEach ($ICLUSTER in $ICLUSTERS){
> $Cluster = $ICLUSTER.cluster
>
> * * * * ForEach ($clusterfile in $clusterfiles){
> * * * * * * $clusfile = $clusterfile.name
> * * * * * * $clusfilename = $clusterfile.split(".")[0] * * * *
>
> * * * * * * * * * * if ($Cluster -notmatch $clusfilename){
> * * * * * * * * * * write-host $Cluster " not match"
> * * * * * * * * * * }#if
>
> * * * * }#foreach
>
> }#foreach
>
> --
> job...@xxxxxx
My System SpecsSystem Spec
Old 05-11-2009   #3 (permalink)
IT Staff


 
 

Re: Comparison of two sets of Data


take note that compare-object compares up to 15 items. Therefore to compare
unlimited items, put:

compare-object -syncWindow $int

where $int is higher of the 2 objects.

Eg

compare-object <source> <target> -syncWindow $int


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Box sets in MB Media Center
A Comparison Graphic cards
Two sets of folders Live Mail
Backup sets Vista General
Running Two Sets Of Speakers Vista General


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