Power shell script to Add primary SMTP address to multiple mailbox in Exchange 2010
I have to add new SMTP address to bulk disabled user mailbox. I have tried the below command and it is working for single user. Remote
Pipeline Execution Failed For bulk users.
Get-Content c:\users.txt | get-mailbox | select-object $_.samaccountname | foreach {Set-Mailbox $_.identity -emailAddressPolicyEnabled:$false
-primarySmtpAddress ("{0}.terminated@domain.com"
-f $_.samaccountname)}
Error while executing for multiple user:
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace)
[],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed
My objective is to replace primary SMTP address with new one in format UserID.terminated@domain.com
May 8th, 2013 3:47pm
Hi
The error you see is because of the multiple pipelines - this can be fixed in a couple of ways.
What format is the users.txt file in because your command could be a lot simpler if it contained either samaccountnames or aliases already ... you could pipe that straight to the foreach?
Also you can shorten this part of the command:
get-mailbox | select-object $_.samaccountname
to this:
(get-mailbox).samaccountname
Steve
Free Windows Admin Tool Kit Click here and download it now
May 8th, 2013 4:01pm
I modified the command
[PS] C:\>Get-Content c:\users.txt | (get-mailbox).samaccountname | foreach {Set-Mailbox $_.identity -primarySmtpAddress
("{0}.terminated@domain.com" -f $_.samaccountname)}
Error:
Expressions are only allowed as the first element of a pipeline.
At line:1 char:57
+ Get-Content c:\users.txt | (get-mailbox).samaccountname <<<< | foreach {Set-Mailbox $_.identity -primarySmtpAddress
("{0}.terminated@domain.com" -f $_.samaccountname)}
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
I modified Users.txt to samaccountname and tried the below command:
[PS] C:\>Get-Content c:\userlist1.txt | foreach {Set-Mailbox $_.identity -primarySmtpAddress ("{0}.terminated@domain.com"
-f $_.samaccountname)}
Error:
Cannot process argument transformation on parameter 'PrimarySmtpAddress'. Cannot convert value ".terminated@domain.com" t
o type "Microsoft.Exchange.Data.SmtpAddress". Error: "".terminated@domain.com" is not a valid SMTP address"
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
May 8th, 2013 5:36pm
On Wed, 8 May 2013 19:36:50 +0000, ritesh_ms wrote:
>I have to add new SMTP address to bulk disabled user mailbox. I have tried the below command and it is working for single user. Remote Pipeline Execution Failed For bulk users.
>
> Get-Content c:\users.txt | get-mailbox | select-object $_.samaccountname | foreach {Set-Mailbox $_.identity -emailAddressPolicyEnabled:$false -primarySmtpAddress ("{0}.terminated@domain.com" -f $_.samaccountname)}
>
>Error while executing for multiple user:
>
>
>Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
> + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
> PSInvalidOperationException
> + FullyQualifiedErrorId : RemotePipelineExecutionFailed
>
>My objective is to replace primary SMTP address with new one in format UserID.terminated@domain.com
How about something nice and simple? No pipes at all.
foreach ($u in (Get-Content c:\users.txt))
{
$m = get-mailbox $u
Set-mailbox $m.distinguishedname -emailAddressPolicyEnabled:$false
-primarySmtpAddress "$($m.samaccountname).terminated@domain.com"}
}
The only problem I see is that you're using ANR to locate the mailbox.
That can be a problem if:
1. There's an empty line in your input file (you'll get ALL mailboxes!
That's probably not what you want.)
2. The values in your input file aren't unique (e.g. you have a user
named "jdick" and anothr named "jdickins"; you may modify more
mailboxes than you intended).
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
May 9th, 2013 1:10am
On Wed, 8 May 2013 19:36:50 +0000, ritesh_ms wrote:
>I have to add new SMTP address to bulk disabled user mailbox. I have tried the below command and it is working for single user. Remote Pipeline Execution Failed For bulk users.
>
> Get-Content c:\users.txt | get-mailbox | select-object $_.samaccountname | foreach {Set-Mailbox $_.identity -emailAddressPolicyEnabled:$false -primarySmtpAddress ("{0}.terminated@domain.com" -f $_.samaccountname)}
>
>Error while executing for multiple user:
>
>
>Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
> + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
> PSInvalidOperationException
> + FullyQualifiedErrorId : RemotePipelineExecutionFailed
>
>My objective is to replace primary SMTP address with new one in format UserID.terminated@domain.com
How about something nice and simple? No pipes at all.
foreach ($u in (Get-Content c:\users.txt))
{
$m = get-mailbox $u
Set-mailbox $m.distinguishedname -emailAddressPolicyEnabled:$false
-primarySmtpAddress "$($m.samaccountname).terminated@domain.com"}
}
The only problem I see is that you're using ANR to locate the mailbox.
That can be a problem if:
1. There's an empty line in your input file (you'll get ALL mailboxes!
That's probably not what you want.)
2. The values in your input file aren't unique (e.g. you have a user
named "jdick" and anothr named "jdickins"; you may modify more
mailboxes than you intended).
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
May 9th, 2013 1:10am