View Single Post
Old 10-08-2008   #6 (permalink)
PaulChavez


 
 

Re: Pipe compare-object results into something useable

In that case the InputObject property of the comparison is the whole line
from the CSV right? I wouldn't think the code as written below would work
correctly, the email address and name would be set to something like "Mickey
Mouse,mmouse@xxxxxx".

To get a different "fields" you can use the split method like this:
new-mailcontact -ExternalEmailAddress "SMTP:$($_.InputObject.split(",")[0])"
-Name "$($_.InputObject.split(",")[1])"

"daystrom" wrote:
Quote:

>
> OK,
>
> Let's take this a step further.
>
> I have two CSV files with a header line on each.
>
> The CSV would look something like this:
>
> Name,Email
> Mickey Mouse,mmouse@xxxxxx
> Donald Duck,dduck@xxxxxx
>
> I need to compare the two CSV's. The output needs to retain the header
> information so I can pass it to another command.
>
>
> Code:
> --------------------
> compare-object (gc list1.csv) (gc list2.csv) | %{if ($_.SideIndicator -eq "<=") {new-mailcontact -ExternalEmailAddress "SMTP:$($_.InputObject)" -Name "$($_.InputObject)"}}
> --------------------
> The above does the trick but I would like to add the name field with the
> proper name and not the email address.
>
> Thank you PowerShell wizards!
>
>
> --
> daystrom
>
My System SpecsSystem Spec