CatherineB-ITSupport
 New Member Posts:2
 |
| 04 Sep 2008 04:17 AM |
|
<!--[if gte mso 9]>
Normal
0
false
false
false
EN-GB
X-NONE
X-NONE
MicrosoftInternetExplorer4
<!--[if gte mso 10]>
I have to keep adding second (third and many more) smtp address to peoples mailboxes for testing purposes, ie:
the user needs to register an email address to test something so I add test1@domain.com to his mailbox, then the week after he needs another 10 adding so test2, test3 etc etc. Currently I am manually going in and adding the smtp addresses using the EMC.
My question is, can this be done via the PS? As exchange doesn’t show me what its done (like when you add a new mail box it displays the script for future reference) after its complete the task I don’t know. I haven’t been able to figure it out. I am a complete novice with PS as I tend to opt for the EMC to do tasks.
Any help would be most appreciated
Catherine |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
CatherineB-ITSupport
 New Member Posts:2
 |
| 04 Sep 2008 05:15 AM |
|
I am not sure what I put where for a user called Elaine Mooney for example with an email of emooney@domain.com it would be $user = Get-Mailbox EMooney $user.emailAddresses+="newsmtp@domain.com" Set-Mailbox $user -emailAddresses $user.emailAddresses < what do I put here? Please forgive me if it sounds a stupid question! Can i put multiple smtp addresses in at the same time? Catherine |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
| 04 Sep 2008 05:51 AM |
|
Hello;
The first line, ($user = get-mailbox emooney) gets the mailbox.
The second line, ($user.emailAddresses += "newsmtp@domain.com") adds the new mail address. Here, you would replace newwsmtp@domain.com with emooney$domain.com. The += in that line takes the existing emailaddresses, and adds the new one.
The third line, (Set-Mailbox $user -emailAddresses $user.emailAddresses) puts the collection of addressses into the mailbox object.
You can add more addresses by adding more lines like the second one, so:
$user
= Get-Mailbox EMooney
$user
.emailAddresses += "emooney@domain.com"
$user
.emailAddresses += "elaine.mooney@domain.com"
$user
.emailAddresses += "elainem@domain.com"
Set-Mailbox
$user -emailAddresses $user.emailAddresses |
|
http://unlockpowershell.wordpress.com
Co-Author, Windows PowerShell 2.0 Bible
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"}) |
|
|
apperrault
 New Member Posts:7

 |
| 22 Sep 2008 10:51 AM |
|
I have a question about this script. My organization is going through a re-branding, and i I need to add a new email address for every user (and distribution list) in our organization, and set that email address as the default Outbound email address. This looks exactly like what i would need, the question i have is how to generate the email addresses for the script. we want everyone to have first.last@company.com, and firstInitialLastname@company.com. Normally i would use the recipient policy, but most of our users have the recipient policy enforcement disabled, since we have recently merged three different organizations, and some people have companyX email addresses, while others have CompanyZ, and others have CompanyA, so i need to script EVERYONE having the new email address.
I am assuming i would do something like this:
$user = Get-Mailbox *
$user.emailaddress+="???????????????????????????" -->What do i put here for First.Last@company.com
Set-Mailbox $user -emailaddresses $user.emailaddresses
Then i would assume i would write a second script that would be:
$user = Get-Mailbox *
$user.emailaddress+="???????????????????????????" --> what do i put here for FirstInitialLastName@company.com
and that would be it for the addition of the second one.
Any thoughts would be greatly appreciated. We are launching our new brand tomorrow, so i need to get this down pat so i can run the script at 6:00am tomorrow morning when we launch
Thanks much
app |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 22 Sep 2008 11:50 AM |
|
Try this: Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach { $user = Get-user $_.distinguishedName if(!$user.firstName -and !$user.lastName -and !$user.Initials){ write-error "user information is not sufficient" break } $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com" $email2= "{0}.{1}{2}" -f $user.Initials[0],$user.lastName, "@company.com" $_.emailAddresses += ($email1,$email2) Set-Mailbox $_ -emailAddresses $_.emailAddresses } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
apperrault
 New Member Posts:7

 |
| 22 Sep 2008 12:04 PM |
|
Shay,
Thanks for this, I will try it out in the AM. One question, from that code, where is the set default mailbox, or is that the set-mailbox $_ -emailAddresses $_.emailAddresses command.
I just want to make sure that i understand the syntax correctly.
thanks
app |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 22 Sep 2008 12:06 PM |
|
You mean the default email address? :
# assuming the default will be the second address
$primary = $email2
# change the set-mailbox line to this
Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
apperrault
 New Member Posts:7

 |
| 22 Sep 2008 12:15 PM |
|
So, if you were going to do this, your script would read:
Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {
$user = Get-user $_.distinguishedName
$primary = $email1
if(!$user.firstName -and !$user.lastName -and !$user.Initials){
write-error "user information is not sufficient"
break
}
$email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com"
$email2= "{0}.{1}{2}" -f $user.Initials?],$user.lastName, "@company.com"
$_.emailAddresses += ($email1,$email2)
Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary
} |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 22 Sep 2008 12:17 PM |
|
Yes, just move the line: $primary = $email1 After the email1,email2 assignment: Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach { $user = Get-user $_.distinguishedName if(!$user.firstName -and !$user.lastName -and !$user.Initials){ write-error "user information is not sufficient" break } $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com" $email2= "{0}.{1}{2}" -f $user.Initials?],$user.lastName, "@company.com" $primary = $email1 $_.emailAddresses += ($email1,$email2) Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
apperrault
 New Member Posts:7

 |
| 22 Sep 2008 12:26 PM |
|
Thanks for the help. I will report back in the AM how it went.
app |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 22 Sep 2008 12:32 PM |
|
There yo go
1. Change all logical -and to -or
2. You can't use both PrimarySMTPAddress and EmailAddresses parameters at the same time (error), so I'm adding a second call to set-mailbox
Here's the last script version, it has been debugged and tested successfully.
Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {
$user = Get-user $_.DistinguishedName
if(!$user.firstName -or !$user.lastName -or !$user.Initials){
write-error "user information is not sufficient"
break
}
$email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@companya.com"
$email2= "{0}{1}{2}" -f $user.Initials[0],$user.lastName, "@companya.com"
$primary = $email2
$_.emailAddresses += ($email1,$email2)
Set-Mailbox $_ -emailAddresses $_.emailAddresses
Set-Mailbox $_ -primarySmtpAddress $primary -emailAddressPolicyEnabled $false
} |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
apperrault
 New Member Posts:7

 |
| 22 Sep 2008 01:24 PM |
|
Thanks much. app |
|
|
|
|
sailingguy
 New Member Posts:3

 |
| 11 Jun 2009 06:54 AM |
|
I'm trying to accomplish something very similar however I need to take current primary SMTP address and write it to the secondary "small" smtp location and take the input from my .csv file and put it in the primary SMTP attribute position. My script will take the input and overwrite the primary but I'm unable to figure out how to stamp the old address intothe smtp attribute. $list = Import-csv c:\Input.csv foreach ($entry in $list) { $newaddressstring = $entry.SMTP $User = $entry.username $oldaddress = get-mailbox -identity $user |select PrimarySmtpAddress set-mailbox -identity $user -PrimarySmtpAddress $newaddressstring -EmailAddressPolicyEnabled $false do{$address = get-mailbox -identity $user |select PrimarySmtpAddress}while ($address.PrimarySmtpAddress.ToString().ToLower() -ne $newaddressstring) $mailbox = Get-Mailbox -identity $user $mailbox.EmailAddresses -= $oldaddress.PrimarySmtpAddress.ToString() set-mailbox -identity $user -EmailAddresses $mailbox.EmailAddresses
|
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
Thiago Di Giorgio
 New Member Posts:3

 |
| 09 Sep 2009 06:53 AM |
|
Hello Shay,
I have modified your script a little bit to fit to my needs, but when I execute I get this error
[PS] C:\>Get-mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach { >> $user = Get-user $_.Name >> $email1= $user,"@teste1.com" >> Set-User $_ -lastname $email1 >> } >> Set-User : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LastName'. Specified method is not s upported. At line:4 char:22 + Set-User $_ -lastname <<<< $email1 [PS] C:\>
What can I do??
Thanks!!!
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 09 Sep 2009 07:00 AM |
|
$email1 is an array, it contains $user in the first element and "@teste1.com" in the second, try this: Get-mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach { $user = (Get-user $_.Name).Name $email1= "$user"@teste1.com" Set-User $_ -lastname $email1 }
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
Thiago Di Giorgio
 New Member Posts:3

 |
| 09 Sep 2009 07:10 AM |
|
Shay, my needs is to add 2 others smtp addresses, but I need to get the name of the user to build the email address, I have modified your script like this and get this error see bellow the script and the results. Thanks!!! [PS] C:\>Get-Mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach { >> $user = (Get-user $_.Name).Name >> $email1= $user,"@teste.com" >> $email2= $user,"@teste1.com" >> $_.emailAddresses += ($email1,$email2) >> Set-Mailbox $_ -emailAddresses $_.emailAddresses >> } >> Exception setting "EmailAddresses": "Cannot convert value "System.Object[]" to type "Microsoft.Exchange.Data.ProxyAddressCollection ". Error: "Conversion from System.Object[] to Microsoft.Exchange.Data.ProxyAddress has not been implemented."" At line:5 char:4 + $_.e <<<< mailAddresses += ($email1,$email2) [PS] C:\> |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 09 Sep 2009 07:13 AM |
|
You are still using a comma in the email address, that's bad. It turns the email address into an array. I aslo had a typo :), Try this: [PS] C:\>Get-Mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach { $user = (Get-user $_.Name).Name $email1= "$user@teste.com" $email2= "$user@teste1.com" $_.emailAddresses += ($email1,$email2) Set-Mailbox $_ -emailAddresses $_.emailAddresses } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
Thiago Di Giorgio
 New Member Posts:3

 |
| 09 Sep 2009 07:42 AM |
|
Shay, you have won a new fun....... It worked, THANK YOU SO MUCH...... Sorry about my stupid mistakes....(this is my first doubt.....) I'm learning a lot now..... Thankssss =) |
|
|
|
|
Mr Coffee
 New Member Posts:5

 |
| 22 Nov 2009 11:14 PM |
|
Question about bulk import of x500 addresses for contacts using a CSV I am trying to add an X500 to a group of contacts using a CSV. I was using the mail attribute to pull the contacts up this is the first column of the csv then I have the x500 of legacyexchangeDN in the second column. I can use this to add an x500 to a group of users but when I attempt to do that to a group of contacts it does not work. I am struggling with even adding the x500 to the contacts at all via powershell. [PS] C:\PSscripts>import-csv UsersX500test.csv | foreach { >> $temp = Get-Contact -identity $_.mail >> $temp.ProxyAddresses += "x500:" + $_.legacyexchangedn >> Set-mailbox -instance $temp}>> I find that this works for user objects but not contacts. Can some one please tell me what I am doing wrong? Any help would be greatly appreciated.
|
|
|
|
|
Mr Coffee
 New Member Posts:5

 |
| 22 Nov 2009 11:29 PM |
|
I think I was pulling contact and not mailcontact. I have not tested yet but I would bet that this fixes things for me. I will post back if that works. |
|
|
|
|
Mr Coffee
 New Member Posts:5

 |
| 23 Nov 2009 12:50 AM |
|
[PS] C:\PSscripts>import-csv UsersX500test.csv | foreach { >> $temp = Get-mailContact -identity $_.mail >> $temp.EmailAddresses += "x500:" + $_.legacyexchangedn >> Set-mailcontact -instance $temp} this is the script that I used to go from legacyexchangeDN to x500 works well when you have 2 forest that will eventually merge together I used a csv with mail attribute in 1st colum then legacy exchangeDN you could use alias but they are diffrent for these obejcts in the 2 forests. I hope it helps some one |
|
|
|
|
kepa
 New Member Posts:7

 |
| 01 Dec 2009 10:43 PM |
|
Hi, I need to add secondary email address to users who have certain value in custom attribute 1. How to accomplish this with PowerShell? We have Exchange Server 2007.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
kepa
 New Member Posts:7

 |
| 01 Dec 2009 11:19 PM |
|
Posted By Shay on 01 Dec 2009 11:48 PM
PowerShell/Exchange version?
Exchange 2007 SP1/PowerShell 1.0. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
kepa
 New Member Posts:7

 |
| 02 Dec 2009 12:25 AM |
|
Posted By Shay on 02 Dec 2009 01:17 AM
All mailboxes share the same value for custom attribute 1?
Yes. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|