Link to home
Start Free TrialLog in
Avatar of osagarana
osagarana

asked on

How to set an automatic X500 SMTP address based on the usermailbox

Hi Experts,

I apologise with my basic request in powershell.
I need to automate some tasks at work and I am trying to put things togheter to have a kind of script in the end.
I need to get all "usermailbox" from a specific organization unit and set automagically a X500 SMTP address.

So far this is why I could reach >>>


Get-User –OrganizationalUnit "OU=Provisional,OU=ORGUNIT,DC=domain,DC=com" | Where-Object{$_.RecipientType –eq “UserMailbox”} | Set-Mailbox $SAMAccountname -EmailAddresses @{Add=’X500:/o=DOMAIN/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=PrimarySmtpAddress'}

Notes:
$SAMAccountname is the accountname from the user
PrimarySmtpAddress is the primary smtp address from the UserMailbox.


The error>>
Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox


I guess my problem now is the $SAMAccountname.
Can someone put in the right direction?
Avatar of SubSun
SubSun
Flag of India image

Try..
Get-Mailbox –OrganizationalUnit "OU=Provisional,OU=ORGUNIT,DC=domain,DC=com" | Where-Object{$_.RecipientType -eq "UserMailbox"} | % {Set-Mailbox $_.SAMAccountname -EmailAddresses @{Add="X500:/o=DOMAIN/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=$($_.PrimarySmtpAddress.tostring())"}}

Open in new window

Or
Foreach ($User in (Get-Mailbox –OrganizationalUnit "OU=Provisional,OU=ORGUNIT,DC=domain,DC=com" | Where-Object{$_.RecipientType -eq "UserMailbox"})) {
Set-Mailbox $User.SAMAccountname -EmailAddresses @{Add="X500:/o=DOMAIN/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=$($User.PrimarySmtpAddress.tostring())"}
}

Open in new window

Avatar of osagarana
osagarana

ASKER

Hi Subsun,

I guess I am almost there.
I had two mailboxes there and SMTP was added just for one object.

Here is the error:


[PS] C:\scripts>Get-mailbox -OrganizationalUnit "OU=Users,OU=MOE,DC=domain,DC=com" | Where-Object{$_.RecipientType -eq "UserMailbox"} | % {Set-Mailbox $_.SAMAccountname -EmailAddresses @{Add="X500:/o=domain/ou=Exchange Administrative Group FYDIBOHF23SPDLT)/cn=Recipients/cn=$($_.PrimarySmtpAddress.tostring())"}}
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

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

[PS] C:\scripts>
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial