Solved

connect to an exchange 2013 address book

Posted on 2014-10-30
5
153 Views
Last Modified: 2014-11-13
Hey guys
I am pretty sure there is a way to do this but just in case I will ask here.  I need to be able to connect to an Exchange 2013 address book with a MS SQL command (search, lookup and insert)  I have a customer who wants to be able to add email addresses automatically from a notification that he receives from his Smart Host provider. Here is how it works.  His Smart Host provider will send notifications every time an email is sent from his domain.   The notifications will contain the sender and recipients name. He want to take the recipients name and see if it's a new address or one he has in his Exchange Address book. If he already has it the application will not add it to the database.  If it's a new one then the application we are creating using SQL server will insert the address.
I think i will probably be told to use Power Shell but just in case you guys have another suggestion I would sure appreciate it
0
Comment
Question by:jonmenefee
  • 3
  • 2
5 Comments
 
LVL 10

Assisted Solution

by:JoeKlimis
JoeKlimis earned 500 total points
ID: 40434882
Hi

I can think of a neat way of doing this , but you could run Powershell commands from sql  

Here is a good example

so you could try  something like this

xp_cmdshell 'PowerShell.exe -noprofile -command "
Add-pssnapin Microsoft.Exchange.Management.Powershell.Admin;  New-MailContact -Name ""Chris Ashton"" -ExternalEmailAddress ""Chris@tailspintoys.com"" -OrganizationalUnit ""Marketing"" "'

Open in new window

0
 

Author Comment

by:jonmenefee
ID: 40437308
That is great code. If the name is already in there would it return an error message?
0
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40437672
It will do exactly the same as on the command line , it would issue you a warning , this can be captured like this


declare @cmdline varchar(500),@ReturnCode int
select @cmdline = 'PowerShell.exe -noprofile -command "Add-pssnapin Microsoft.Exchange.Management.Powershell.Admin;  New-MailContact -Name ""Chris Ashton"" -ExternalEmailAddress ""Chris@tailspintoys.com"" -OrganizationalUnit ""Marketing"" "'

create table #temp (PsErrors varchar(500))
insert #temp
EXEC @ReturnCode = master.dbo.xp_cmdshell @cmdline

if @ReturnCode <> 0
select * from #temp
where PsErrors is not null

Open in new window

0
 

Author Comment

by:jonmenefee
ID: 40437688
That is perfect!   So I just need to modify it to my server and the last one you sent is what I would use in SQL. :-)   thanks!!
0
 

Author Closing Comment

by:jonmenefee
ID: 40441791
Great help  Thank you very much!!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question