View Single Post
Old 10-07-2008   #2 (permalink)
PaulChavez


 
 

RE: Pipe compare-object results into something useable

Here is a sample of how to use compare-object, just replace the string with a
call to a function that does the desired operation.

compare-object (gc list1.txt) (gc list2.txt) |
%{
if ($_.SideIndicator -eq "<=") {"$($_.InputObject) exists in file 1"}
if ($_.SideIndicator -eq "=>") {"$($_.InputObject) exists in file 2"}
}


"daystrom" wrote:
Quote:

>
> I'm sure this can be done but I don't know where to start...
>
> This will eventually make it's way into Exchange Management Shell. What
> I need to do is compare two text files that contain email addresses, one
> per line.
>
> If file A contains an email address that file B doesn't have, add it as
> a contact in AD.
> If file B has an email address that isn't in file A, remove its contact
> from AD.
> Then overwrite file B with file A so the next day's run will be in
> sync.
>
> I'm trying to build distribution lists that contain external addresses.
> In Exchange 2007 you need to have a contact in your AD to add the user
> to a distribution list.
>
> I'm trying to automate the whole create/delete a contact in AD. Our ERP
> system which runs on Sun OS generates the source text file with email
> addresses nightly (whether there has been a change or not). If I could
> use this output and compare its content with a second file I may be able
> to accomplish what I want.
>
> Can this be done?
> Todd
>
>
> --
> daystrom
>
My System SpecsSystem Spec