Wednesday, September 18, 2013

Powershell - Report on Distribution Groups with AcceptMessageOnlyFrom set

9/18/2013: My day job is as a Messaging & Collaboration admin, running 33,000 mailboxes for Hexaware/Unisys. And because I spend most of my day working with Exchange 2010 & 2007, I make a ton of routine use of Powershell, to automate routine tasks, multitask, and generally get more done in less time. The way I look at it, anything I need to do more than once or twice, can probably benefit from taking a little time to code it out and automate it Powershell.

And since I've gotten tons of useful tips and scripting examples from folks like Paul Cunningham  and Shay Levy, I've decided to give back some tips & code-bits to help other folks quickly tackle their own admin needs with Powershell & Exchange Management Shell.

Report on Distribution Groups with AcceptMessageOnlyFrom set
Toward that end, here's a piece of code I put together some time ago, to pull out all Distribution Groups with the AcceptMessagesOnlyFrom, and then concatonate together the AcceptMessagesOnlyFrom strings, and export the results to CSV file.



Get-DistributionGroup -filter { AcceptMessagesOnlyFrom -ne $null} | 
select Name,@{Name="AcceptMessagesOnlyFrom";Expression={ `
[string]::join(";",$_.AcceptMessagesOnlyFrom) } } |
export-csv .\dlacceptmessages.csv -notype

Typical output csv contents: (heading and first line)
"Name","AcceptMessagesOnlyFrom"
"X Domain Admins","OU/United States/Users/Blow, Joe;OU/United States/Users/Blow, Josie"


The components of the command used are a simple Get-DistributionGroup command leveraging the -filter parameter to retrieve matches, piped into a Select command that retrieves the Name attribute and a custom field that joins the multiple AcceptMessageOnlyFrom strings into a single semi-colon-delimited string. The export-csv then outputs the Name & AcceptMessagesOnlyFrom values to the specified CSV file.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.