Adding a User to Multiple Exchange Distribution Lists Using Windows PowerShell

PowerShell command line window

Adding a user to multiple distribution lists via Outlook can be a tedious process if many lists are involved. For today’s problem, I had to add a user to many lists that have a similar prefix. Instead of spending a an hour or more of adding the user to the DLs through the Global Address Book, I decided to use PowerShell.

This script, which I call “addtodl.ps1”, receives three parameters: the user’s email address, the name of the distribution list – which can include a wildcard character (*) to get multiple names, and the Exchange Server FQDN.

Param(
	[string] $UserName,
	[string] $DLName,
	[string] $Exchange
)

$exch = "http://" + $Exchange + "/PowerShell/?SerializationLevel=Full"

$Credentials = Get-Credential
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exch -Credential $Credentials -Authentication Kerberos
Import-PSSession $ExSession

$distlists =  Get-DistributionGroup $DLName

foreach ($distlist in $distlists) {
	Add-DistributionGroupMember -Identity $distlist.PrimarySmtpAddress -Member $UserName
	#$ManagedBy = $distlist.ManagedBy
	#foreach ($owner in $ManagedBy) {
	#	echo $owner
	#}
}

Exit-PSSession
Remove-PSSession -ID $ExSession.ID
[GC]::Collect()

By running this at the PowerShell command line with the parameters, you will be able to add the user to all distribution lists in the query that you manage. Those that you do not have access to will cause an error that will not halt the script. A dialog box asking for your username and password will appear first.

PowerShell command line window

When I have time, I intend to revisit this issue to get more useful information such as owner email addresses. Currently, if you uncomment the lines inside the foreach statement, the owners of each DL will be printed on the screen as well. It’s not too useful yet – which is why I still have it commented here.

Problems with the Out of Office Indicator and Status Message on Microsoft Lync 2010

Microsoft Lync 2010 logo

This isn’t a software development problem per se, but it was a technical problem I had with Lync that does not appear to have been documented, based on my searches.
In an enterprise environment where Microsoft Lync is integrated with Exchange, Lync has an indicator that shows if your Out of Office Assistant (OoOA) in Outlook is turned on.  It appears as a little red asterisk in the lower right-hand corner of the status light.  Also, your Lync status message is automatically set to whatever your OoOA internal message is.

If you set your OoOA to be turned on and off at a scheduled time, the Lync features will be activated when the start time passes.  The problem I had was that even when the end time had passed and Outlook’s feature had been turned off automatically, Lync’s feature remained on.  Even changing the status message in Lync manually did not work; it was immediately reset to the one set up in Outlook.  Closing and reopening both Lync and Outlook had no apparent effect.

I discovered that if I manually activated the OoOA and then manually deactivated it, Lync was once again properly synched up with Exchange and the red asterisk and status message reverted to their default states.