Dynamic Distribution Group Viewer (Sharepoint 2010 Webpart)
Introduction
Lots of organizations / companies use dynamic distribution groups in Exchange. While these groups allow for low administrative overhead, they dont allow users to know who the email is going to until the email has been sent. This sharepoint webpart allows users to see who is in a group before the email is sent.
Using the Code
Before you begin you must have the Exchange Management Console installed on your server. If you are planning to deploy this in sharepoint, you will also need to edit your web.config to read:
<trust level="Full" originUrl="" />
In Visual Studio 2010 create a new Empty SharePoint Project. Add a new Visual Web Part Item. Add the System.Management.Automation reference to your project. Include the following 3 items in your using:
using System.Management.Automation; using System.Management.Automation.Host; using System.Management.Automation.Runspaces;
We need to open the Exchange management PowerShell snappin
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn ("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig); myRunSpace.Open();
Next we need to send the cmdlet into powershell. In this case I am asking to Get-DynamicDistributionGroup with the groupName being a variable I had the user select from a drop down.
Pipeline pipeLine = myRunSpace.CreatePipeline(); Command myCommand = new Command("Get-DynamicDistributionGroup"); CommandParameter identityParam = new CommandParameter("Identity", groupName); myCommand.Parameters.Add(identityParam); pipeLine.Commands.Add(myCommand); Collection<PSObject> commandResults = pipeLine.Invoke(); PSObject distGroup = commandResults[0]; Runspace recipientRunSpace = RunspaceFactory.CreateRunspace(rsConfig); recipientRunSpace.Open();
Once we have the Dynamic Distribution Group's Name, we need its recipients.
pipeLine = recipientRunSpace.CreatePipeline(); myCommand = new Command("Get-Recipient"); if (distGroup.Members["RecipientFilter"] != null && distGroup.Members["RecipientFilter"].Value.ToString().Length > 0) { CommandParameter recipientFilter = new CommandParameter ("RecipientPreviewFilter", distGroup.Members["RecipientFilter"].Value); myCommand.Parameters.Add(recipientFilter); } CommandParameter OU = new CommandParameter("OrganizationalUnit", distGroup.Members ["RecipientContainer"].Value.ToString()); myCommand.Parameters.Add(OU); pipeLine.Commands.Add(myCommand); commandResults = pipeLine.Invoke();
Next I build a list of all the user's names from that group. The list of names is then bound to a bulleted List.
List<string> nameList = new List<string>(); foreach (PSObject cmdlet in commandResults) { if (cmdlet.Properties["Name"] != null && cmdlet.Properties["Name"].Value.ToString().Length > 0) { string recipientName = cmdlet.Properties["Name"].Value.ToString(); nameList.Add(recipientName); } } BulletedList1.DataSource = nameList; BulletedList1.DataBind();
The last thing I did was change the DisplayMode of the bulleted list to LinkButton. This makes the user's names hyperlinks which go to the sharepoint MySite page.
protected void BulletedList1_Click(object sender, BulletedListEventArgs e) { ListItem li = BulletedList1.Items[e.Index]; Response.Redirect("http://sharepoint peoplesearch URL" + BulletedList1.Items[e.Index].Text); }
发表评论
this side of your story. I was surprised that you aren at
Just because they call it advanced doesn at mean it is.
Wow! This could be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Great. I am also a specialist in this topic therefore I can understand your effort.
You ave made some really good points there. I looked on the web for additional information about the issue and found most individuals will go along with your views on this web site.
Thanks again for the post.Really looking forward to read more. Fantastic.
Wonderful web page. Numerous valuable data here. We are delivering that to several mates ans also revealing inside delectable. And of course, interesting work!
I want forgathering utile information , this post has got me even more info!.
love to write some material for your blog in exchange for a link back to mine.
We stumbled over here different page and thought I may as well check things out. I like what I see so i am just following you. Look forward to looking into your web page repeatedly.
This is my first time go to see at here and i am in fact impressed to read everthing at single place.
that site What computer brands allow you to build your own computer?
Looking forward to reading more. Great post.Really looking forward to read more. Fantastic.
Some genuinely select posts on this web site , saved to fav.
i use google when i want to do some spanish translation, it is good for general spanish translation.,
Keep up the great writing. Visit my blog ?????? (Twyla)
Right now it appears like BlogEngine is the top blogging platform out there right now. (from what I ave read) Is that what you are using on your blog?
Really clear website , appreciate it for this post.
You made some clear points there. I did a search on the topic and found most people will go along with with your blog.
If you are concerned to learn Web optimization methods then you have to read this post, I am sure you will get much more from this piece of writing concerning Search engine marketing.
I wanted to thank you for this fantastic article, I certainly loved every small bit of it. I have bookmarked your web site to look at the newest stuff you post.
With thanks for sharing this excellent web-site.|
Thanks so much for the article post.Really looking forward to read more. Will read on
Woah! I am really enjoying the template/theme of this blog. It as simple, yet effective. A lot of times it as tough to get that perfect balance between usability and visual appearance.
Thanks for sharing this great post. Very interesting ideas! (as always, btw)
You created some decent points there. I looked on line for that concern and located most of the people will go coupled with with all of your web site.
This site truly has all of the information and facts I needed about this subject and didn at know who to ask.
writing like yours nowadays. I honestly appreciate people like you!
Wow! Thank you! I always wanted to write on my blog something like that. Can I implement a part of your post to my website?
Im obliged for the blog article. Much obliged.
Thanks again for the post.Much thanks again. Really Great.
You have remarked very interesting points ! ps nice website.
Thanks for the blog.Much thanks again. Really Cool.
Thank you ever so for you blog article.Much thanks again. Awesome.
Really informative blog.Really looking forward to read more. Awesome.
Your style is unique in comparison to other folks I ave read stuff from. Thanks for posting when you have the opportunity, Guess I all just book mark this site.
Thanks again for the blog post.Much thanks again. Want more.
Muchos Gracias for your article post.Thanks Again. Awesome.
Your posts customarily consist of a correct amount of truly up to date information. Everyplace accomplish you extend up with this? Emphatically declaring you are fantastically creative. Thanks again
That is a great tip particularly to those new to the blogosphere. Simple but very precise info Appreciate your sharing this one. A must read post!
Magnificent website. Lots of helpful info here. I'аm sending it to a few friends ans also sharing in delicious. And certainly, thanks on your sweat!
Thanks so much for the blog article.Really looking forward to read more. Keep writing.
Thanks for sharing, this is a fantastic blog article.Thanks Again. Really Great.
Saved as a favorite, I like your website!
Some genuinely fantastic blog posts on this website , thanks for contribution.
I truly appreciate this article.Really looking forward to read more. Really Cool.
Ultimately, a problem that I am passionate about. I have looked for details of this caliber for the previous various hrs. Your internet site is tremendously appreciated.
You made some decent points there. I did a search on the subject and found most guys will agree with your blog.
I simply could not leave your web site before suggesting that I really enjoyed the standard info an individual supply for your visitors? Is gonna be again steadily to inspect new posts
Im no pro, but I suppose you just crafted an excellent point. You undoubtedly know what youre speaking about, and I can really get behind that. Thanks for staying so upfront and so truthful.
Say, you got a nice article.Really thank you! Great.