short1uk
 New Member Posts:2
 |
| 04 Sep 2008 01:17 PM |
|
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
 Basic Member Posts:214
 |
| 04 Sep 2008 01:39 PM |
|
$user = Get-Mailbox userName $user.emailAddresses+="test123@domain.com" Set-Mailbox $user -emailAddresses $user.emailAddresses |
|
|
|
|
short1uk
 New Member Posts:2
 |
| 04 Sep 2008 02:15 PM |
|
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 |
|
|
|
|
KarlMitschke
 Basic Member Posts:144
 |
| 04 Sep 2008 02:51 PM |
|
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 |
|
|
|
|
apperrault
 New Member Posts:5
 |
| 22 Sep 2008 07:51 PM |
|
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
 Basic Member Posts:214
 |
| 22 Sep 2008 08:50 PM |
|
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 } |
|
|
|
|
apperrault
 New Member Posts:5
 |
| 22 Sep 2008 09: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
 Basic Member Posts:214
 |
| 22 Sep 2008 09: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 |
|
|
|
|
apperrault
 New Member Posts:5
 |
| 22 Sep 2008 09: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
 Basic Member Posts:214
 |
| 22 Sep 2008 09: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 } |
|
|
|
|
apperrault
 New Member Posts:5
 |
| 22 Sep 2008 09:26 PM |
|
Thanks for the help. I will report back in the AM how it went.
app |
|
|
|
|
Shay
 Basic Member Posts:214
 |
| 22 Sep 2008 09:28 PM |
|
Don't go yet, I have some last minute changes, watch this thread in the next minutes. I'm working on it as we *spaek* |
|
|
|
|
Shay
 Basic Member Posts:214
 |
| 22 Sep 2008 09: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
} |
|
|
|
|
apperrault
 New Member Posts:5
 |
| 22 Sep 2008 10:24 PM |
|
Thanks much. app |
|
|
|
|