![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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 Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
|
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Member | Pipe compare-object results into something useable 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 |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | 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:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) |
| Member | Re: Pipe compare-object results into something useable Thank you! That is a start and I think I can build on that. |
My System Specs![]() |
| | #4 (permalink) | ||||||||||||
| Guest | Re: Pipe compare-object results into something useable Just remember to sort your lists first and/or set the SyncWindow parameter, especially if the lists are long... Arnoud -- http://www.jansveld.net/powershell "daystrom" wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) |
| Member | Re: Pipe compare-object results into something useable 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@disney.com Donald Duck,dduck@disney.com 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)"}}
Thank you PowerShell wizards! |
My System Specs![]() |
| | #6 (permalink) | ||||||||||||
| Guest | 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:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #7 (permalink) |
| Member | Re: Pipe compare-object results into something useable This does exactly what I want now. If the contact is on the left side and not the right it will create a mail contact in Exchange. With a little modification if it exists on the right and not left it will remove the contact. You are a wizard! Thanks! Todd |
My System Specs![]() |
|
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare-Object and Get the name of object/File? | akcorr | PowerShell | 5 | 06-19-2008 05:15 AM |
| insert object in pipe | William Stacey [C# MVP] | PowerShell | 3 | 12-04-2006 12:16 AM |
| Testing object arrays using Compare-Object and -contains | Alex K. Angelopoulos [MVP] | PowerShell | 2 | 08-31-2006 05:57 PM |
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | Alex K. Angelopoulos [MVP] | PowerShell | 2 | 05-26-2006 07:58 AM |