Here is the PowerShell script I've been working on (.NET question is at the bottom):
### setup SQL connection
$conn = new-object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "server=*****;database=****;UID=*****;PWD=**** *"
### setup SQL command
$cmd = new-object System.Data.SqlClient.SqlCommand
### Get SQL commands from text file
$cmd.CommandText = get-content h:\scripts\vistar_sql.txt
$cmd.Connection = $conn
###setup SQL adapter to fill in info
$adapter = new-object System.Data.SqlClient.SqlDataAdapter
$adapter.SelectCommand = $cmd
### Create dataset object (.NET Class representing an in-memory cache of data)
$ds = new-object System.Data.DataSet
### fill object with SQL data
$nRecs = $adapter.Fill($ds)
### output to host how many contacts in vistar.
Write-Host ($nRecs.ToString() + " Vistar Contacts retrieved.")
###Close the SQL connection
$conn.close()
###add column to .NET dataset table
$full_name = new-object "System.Data.DataColumn" ("full_name", [string])
$ds.Tables[0].Columns.add($full_name)
$email = @($ds.Tables[0] | foreach { $_.email.trimend() }) | sort
$mso_email = @(get-mailcontact -Organizationalunit "mso" | foreach {$_.externalEmailAddress} | foreach {$_.smtpaddress}) | sort
write-host ($mso_email.count.tostring() + " Total contacts in MSO Exchange OU")
### stores email addresses in array $email
$email = @($ds.Tables[0] | foreach { $_.email.trimend() }) | sort
$diff = diff -syncwindow 525 $email $mso_email
$vistar_only = $diff | % { if ($_.SideIndicator -match '<=') {$_.InputObject}}
write-host ($vistar_only.count.tostring() + " Contacts only in Vistar")
$mso_only = $diff | % { if ($_.SideIndicator -match '=>') {$_.InputObject}}
write-host ($mso_only.count.tostring() + " Contacts only in MSO Exchange OU")
$mso_only = $diff | % { if ($_.SideIndicator -match '=>') {$_.InputObject}} | remove-mailcontact
The script is going to be used to keep a SQL database in Sync with Exchange 2007 contacts, so that external people can in included in e-mail distribution lists.
The current issue that I have is that the properties of the Exchange mailcontact object includes the "name" property which is in the lastname, firstname format. The properties of the .NET dataset table include a lastname property and a firstname property. So I figured out how to add a new property to that .NET object / table, but I can't figure out how to fill that column / rows. If you could take a look at the code and LMK what you think, it would be appreciated.
Thanks,
-Nick