Changing email addresses to lowercase

by jiska78 at 2012-09-26 19:10:39

I’ve updated by Email address policies as follows, which obviously converts email addresses to lowercase:
%rAa%rBb%rCc%rDd%rEe%rFf%rGg%rHh%rIi%rJj%rKk%rLl%r Mm%rNn%rOo%rPp%rQq%rRr%rSs%rTt%rUu%rVv%rWw%rXx%rYy %rZz%1g%s@domain.com.au

Changing that, however, won’t alter existing email addresses as MS doesn’t recognise case. Therefore I created the following PowerShell script to run through and change all the email addresses, but I’m getting the errors below. I must confess I’m not all that proficient at PowerShell, just learning at the moment, so any pointers would be appreciated.


Get-Mailbox | foreach {

for ($i = $.EmailAddresses.Count ;$i -ge 0; $i – )
{
$
.EmailAddresses[$i].ProxyAddressString
}
set-mailbox $.Identity -EmailAddressPolicyEnabled $false
set-mailbox $
.Identity -EmailAddresses $.EmailAdresses.ToLower()
set-mailbox $
.Identity -EmailAddressPolicyEnabled $true
}


Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdlet HelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdlet HelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed

ForEach-Object : You cannot call a method on a null-valued expression.
At C:\a.ps1:1 char:22
+ Get-Mailbox | foreach <<<< {
+ CategoryInfo : InvalidOperation: (ToLower:String) [ForEach-Object], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull,Microsoft.PowerShell.Commands.F orEachObjectCommand
by Helmto108 at 2012-09-30 13:58:55
Hello,

You can try wrapping () around Get-Mailbox, or assign the list of mailboxes to a variable and use that. Also, I believe that attribute that contains email addresses is ProxyAddresses, and not EmailAddresses.

Regards,
Helmto108