header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Script to add new Primary SMTP address
Last Post 24 Feb 2012 12:03 PM by Jeff G. 53 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Page 2 of 2 << < 12
Author Messages
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 05:36 AM
Can you share the csv column header line?

Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 05:40 AM
csv header

tuser1,test.a.user@abc.local

This is exactly what is in the csv file (alias,newemailaddress)
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 05:40 AM
csv header

tuser1,test.a.user@abc.local

This is exactly what is in the csv file (alias,newemailaddress)
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 05:40 AM
csv header

tuser1,test.a.user@abc.local

This is exactly what is in the csv file (alias,newemailaddress)
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 05:40 AM
csv header

tuser1,test.a.user@abc.local

This is exactly what is in the csv file (alias,newemailaddress)
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 05:43 AM
In the script file replace '$_.Identioty' with '$_.alias', and '$_.ExtrenalAddress' with '$_.newemailaddress'. Now try again.

Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 06:02 AM
Thanks Still No joy

this is what I see in the powershell window for the script

Import-Csv c:\mailboxUsers.csv | Foreach-Object{
$mbx = Get-Mailbox -Identity $_.alias
$EmailAddresses = $mbx.EmailAddresses += $_.newemailaddress # add new extrenal address
Set-Mailbox $mbx -EmailAddresses $EmailAddresses -EmailAddressPolicyEnabled $false # uncheck recipient policy and add extrenal address
Set-Mailbox $mbx -PrimarySmtpAddress $_.ExtrenalAddress # set a new primary address
}

This is in the results window

PS C:\Program Files\Microsoft\Exchange Server\Scripts> C:\Program Files\Microsoft\Exchange Server\Scripts\import5.ps1

It does not fail but it does not do anything either the account I am using has full AD / Exchange permisisons

Not sure why it will not work for me
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 06:14 AM
Have you checked the mailboxes? No new email addresses are present on them?

Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 06:43 AM
Yes, I have checked and waited for replication since it is a Virtual machine but still nothing its almost like it is not reading the input file but neither the recipient policy checkmark or the email address are touched when the script is executed
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 06:58 AM
$mbx = Get-Mailbox -Identity TestUser
$EmailAddresses = $mbx.EmailAddresses += 'testuser@domain.com' # add new extrenal address
Set-Mailbox $mbx -EmailAddresses $EmailAddresses -EmailAddressPolicyEnabled $false # uncheck recipient policy and add extrenal address
Set-Mailbox $mbx -PrimarySmtpAddress $_.ExtrenalAddress # set a new primary address


(Get-Mailbox TestUser).EmailAddresses

Does this work?


Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 07:10 AM
This is what I get when i run the new ps1 file keep in mind i changed the testuser alias to match mine tuser1 alias

The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\Microsoft\Exchange Server\Scripts\import8.ps1:1 char:19
+ $mbx = Get-Mailbox <<<< -Identity TUser1
+ CategoryInfo : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Property 'EmailAddresses' cannot be found on this object; make sure it exists and is settable.
At C:\Program Files\Microsoft\Exchange Server\Scripts\import8.ps1:2 char:24
+ $EmailAddresses = $mbx. <<<< EmailAddresses += 'testuser@domain.com' # add new extrenal address
+ CategoryInfo : InvalidOperation: (EmailAddresses:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

The term 'Set-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\Microsoft\Exchange Server\Scripts\import8.ps1:3 char:12
+ Set-Mailbox <<<< $mbx -EmailAddresses $EmailAddresses -EmailAddressPolicyEnabled $false # uncheck recipient pol
icy and add extrenal address
+ CategoryInfo : ObjectNotFound: (Set-Mailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

The term 'Set-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\Microsoft\Exchange Server\Scripts\import8.ps1:4 char:12
+ Set-Mailbox <<<< $mbx -PrimarySmtpAddress $_.ExtrenalAddress # set a new primary address
+ CategoryInfo : ObjectNotFound: (Set-Mailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 07:20 AM
What's your Exchange version?

Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
ceasarliUser is Offline
New Member
New Member
Posts:12
Avatar

--
10 Feb 2011 07:34 AM
Exchange 2007 SVC PAck 2
Shay LevyUser is Offline
PowerShell MVP, Admin
Veteran Member
Veteran Member
Posts:1362
Avatar

--
10 Feb 2011 07:42 AM
You need to load the Exchnage snap-in first, put the following command at the top of the script

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy
brian.wingUser is Offline
New Member
New Member
Posts:1
Avatar

--
25 Feb 2011 08:29 AM
Hey Shay,
some of this post has me feeling like I might be able to do what I need to do.

I need to set the email/mail attribute of an AD user (these users do not have exchange mail accounts) The accounts will be used for LDAP authentication and need email addresses associated with them.

All of the users exist in a single OU in AD and I'd like to do something along the lines of get-qaduser -organizationalunit "OU" |set-qaduser -email (and use firstname.lastname@domain.com) but I'm not sure how to set up variables and then pipe them into the set command.

Any thoughts on how I could make that happen?

Thanks
Brian
kevinjimenezUser is Offline
New Member
New Member
Posts:1
Avatar

--
24 May 2011 07:39 AM
hey shay i am new to this power shell stuff. I need a script that sets email alias to primary, on exchange 2003?
eric25User is Offline
New Member
New Member
Posts:1
Avatar

--
02 Jun 2011 01:46 PM
Hi Shay, I am trying something very similar. But having some problems with the importcsv. I would like to enable Email Address Policy for a large group of users. I am not sure the best way to identify Identity.

I am using the command Import-Csv "C:\temp\email_user.csv" | foreach (Set-Mailbox -EmailAddressPolicyEnabled $false). But that prompts me for the Identity, I can’t seem to get the right command to pull the identity from the csv. Any help would be appreciated. thanks
mr_evans2uUser is Offline
New Member
New Member
Posts:32
Avatar

--
10 Jun 2011 11:27 AM
Hello Shay,
I have a similar issue. I did have my code adding a new primary SMTP address (which worked) but have been asked, to use the primary from the source db and assign that to the db in the new forest.
When I run this I'm getting
Set-Mailbox : Cannot bind parameter 'PrimarySmtpAddress'. Cannot convert the "@
{PrimarySmtpAddress=test-user@company.com}" value of type "Selected.Micros
oft.Exchange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Dat
a.SmtpAddress".

What do I need to do to pass the correct format of the primary SMTP address?


$UserList = "D:\Get-Mailbox\userlist.txt"

Get-Content $UserList | ForEach {
$database = Get-Mailbox -Identity $_ | select -expand database
$smtp = Get-Mailbox -Identity $_ | select PrimarySmtpAddress
Move-Mailbox $_ -TargetDatabase $database -IncludeFolders \Contacts -AllowMerge -SourceForestCredential $SourceCredential -SourceForestGlobalCatalog xxxxxxxx.comany.com -TargetForestCredential $TargetCredential -IgnorePolicyMatch:$true
Set-Mailbox -Identity $_ -primarySMTPaddress $smtp
}
mr_evans2uUser is Offline
New Member
New Member
Posts:32
Avatar

--
10 Jun 2011 12:49 PM
disregard my question please. I was able to get it working
Khemarin SetUser is Offline
New Member
New Member
Posts:1
Avatar

--
02 Sep 2011 03:15 AM
Hi,
I have sample CSV:
ID FirstName LastName UserID
100000 Chetra Chim chimc
200000 Jackie Hello Jonh Dr jackiedr

This is my sample script:
$credential = Get-Credential
Import-Csv allusers.csv | foreach {New-mailbox -Name ($_.FirstName + " " + $_.LastName) -firstname $_.FirstName -lastname $_.LastName -alias $_.UserID -PrimarySmtpAddress ([string]::join('',$_.FirstName.split(" ")) + "." + [string]::join('',$_.LastName.split(" ")) + "@hello.com") -OrganizationalUnit "exchange.local/users" -UserPrincipalName ($_.UserID + "@exchange.local") -LinkedMasterAccount $_.UserID + "@hello.com" -LinkedDomainController "dc01.hello.com" -LinkedCredential $credential}

My result will get:
Name: Jackie Hello Jonh Dr
First Name: Jackie Hello
Last Name: Jonh Dr
UPN: jackiedr@exchange.local
LMA: jackiedr@hello.com
Email SMTP: JackieHello.JonhDr@hello.com (FirstName.LastName@hello.com)

But my syntax error. it cannot verify + symbol.
Noted: Here is the linked mailbox. With AD, I can use + symbol but exchange cannot.
Do you have any idear?
BR,
Khemarin
jagomes16User is Offline
New Member
New Member
Posts:3
Avatar

--
05 Oct 2011 07:18 AM
Hi Shay, you have provided some awesome suggestions.  Can I ask you for a script to add  .com as an alias address to all mailboxes in the organization.  Some of them may already have it so if you could provide suggestions on how to script for addition and also how to remove duplications.  The primary address for now still remains the .ca address.  Also, I would like the take the addresses that are already there and modify them by adding .com as an alias.

Thanks.
NeocrypticaUser is Offline
New Member
New Member
Posts:2
Avatar

--
20 Feb 2012 11:00 AM
Greetings Shay,

I have a similar task, but I have to enable-mailbox on 494 users that don't presently have mailboxes. I have used sort of a version of your script to try this (several different methods). I have to filter out the users that are already mail enabled and only enable the ones that aren't. After reading I am almost positive that the $_.firstName and $_.lastName variables are null, because I get the "".@mydomain.org" is not a valid smtp address when I use the following script:
-------------------------------------------------------------------------------------

$domain=[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

$domain = $domain.forest.name

Get-User -OrganizationalUnit "MY_OU" | Where-Object {$_.RecipientType -eq "User"} | Enable-Mailbox -Database "MyExchServer\MyStorageGroup\MyDB" -PrimarySmtpAddress ("{0}.{1}@{2}" -f $_.firstName,$_.lastName,$domain) -emailaddresspolicyenabled $false

--------------------------------------------------------------------------------------
NeocrypticaUser is Offline
New Member
New Member
Posts:2
Avatar

--
20 Feb 2012 11:29 AM

Hey again Shay,

Scratch my previous request.  I figured it out.  Works like a champ too :)
Below is the code:

---------------------------------------------------------------------------

$domain=[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$domain = $domain.forest.name

Get-User -OrganizationalUnit "My_OU" -RecipientTypeDetails user | Where {$_.firstName -and $_.lastName} | foreach {Enable-Mailbox $_.Identity -Database "MyExchSvr\MyDB" -PrimarySmtpAddress ("{0}.{1}@{2}" -f $_.firstName,$_.lastName,$domain)}

-----------------------------------------------------------------------------

Cheers

Jeff GUser is Offline
New Member
New Member
Posts:2
Avatar

--
24 Feb 2012 12:03 PM
Shay, can you or anyone help debug this? I grabbed the code above to add a secondary address to the EmailAddresses field. It works great with one exception. If the value already happens to exist in the collection it wipes out all the values in the field and leaves it NULL. The easy test is to run the script twice. On the second pass it clears the EmailAddresses field and throws an exception stating the value is already present in the collection.

Here's what I'm using:

param ([string]$CSVList = $null)
Import-Csv $CSVList | Foreach-Object{
$mbx = Get-Mailbox -Identity $_.Identity
$EmailAddresses = $mbx.EmailAddresses += $_.NewAddress # add new extrenal address
Set-Mailbox $mbx -EmailAddresses $EmailAddresses -EmailAddressPolicyEnabled $false # uncheck recipient policy and add extrenal address
}
You are not authorized to post a reply.
Page 2 of 2 << < 12


Active Forums 4.3
right
footer   footer
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
footer   footer