PS-Newbie
 New Member Posts:2

 |
| 06 Nov 2008 03:20 PM |
|
<!--[if gte mso 9]>
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
MicrosoftInternetExplorer4
<!--[if gte mso 10]>
First, I'm very new to PowerShell and I'm not completely understanding what I've read so far.
What I need is a PowerShell script that will read an input file which contains the exchange alias and will uncheck the "automatically update e-mail addresses based on recipient policy" box and create a new email address in the format of firstname.lastname@domain.com and make that new SMTP address the default/primary address. E-Mail Address Policy isn't going to work in this situation.
I've seen the following code which I'm thinking will do part of what I want. So my question is, can the people who are way more knowledgeable in PowerShell help me make this script do the things I described above -- please?
Import-Csv ".\email_user.csv" | foreach {
$fn = $_.firstname
$ln = $_.lastname
Get-Mailbox * | foreach { $_.emailAddresses += ("{0}.{1}@domain.com" -f $fn, $ln) ; $_ } | Set-Mailbox
}
Thanks!
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 07 Nov 2008 06:56 AM |
|
Try this, it will create the new email address and set it as the default address, it also turns off the E-Mail Address Policy flag. The command is based on the following csv file structure: # sample csv file # alias,firstName,lastName shayAlias,shay,levy Import-Csv ".\email_user.csv" | foreach { Set-Mailbox $_.alias -PrimarySmtpAddress ("{0}.{1}@domain123.com" -f $_.firstname,$_.lastname) -EmailAddressPolicyEnabled $false } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
PS-Newbie
 New Member Posts:2

 |
| 07 Nov 2008 10:05 AM |
|
Thank you very much. This script works perfectly. |
|
|
|
|
basecoat
 New Member Posts:6

 |
| 31 Dec 2008 12:18 AM |
|
This is just what im looking for. But I'm kinda new to this, so I got some questions: 1. this part: Import-Csv ".\email_user.csv" only makes a file called email_user.csv? 2. I've got exchange 2007, and I would like to try this script out on only one user ( in case i F**K everything up ). How could I do that? |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 31 Dec 2008 09:42 AM |
|
Import-Csv creates objects from comma-separated files. See the help for more inforamtion and code examples:
PS > help import-csv -full
The example I posted above works on a single user, so chahnge the values (e.g shayAlias,shay,levy ) to your own and test it. BTW, most PowerShell cmdlet support the -whatIf parameter.WhatIf describes what would happen if you executed the command without actually executing the command. |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
basecoat
 New Member Posts:6

 |
| 02 Jan 2009 02:32 AM |
|
Great it works!! Thanks! Now if I want to do this for everyone on my exchange 2007 server i would have to make a csv file with all the names? Any quick tip on how i could do that without writing it all manually? |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 03 Jan 2009 09:24 AM |
|
You can do it without a csv file, just replace import-csv with Get-Mailbox and pipe directly to foreach: Get-Mailbox -resultSize unlimited | foreach { Set-Mailbox $_.alias -primarySmtpAddress ("{0}.{1}@domain123.com" -f $_.firstname,$_.lastname) -emailAddressPolicyEnabled $false }
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
basecoat
 New Member Posts:6

 |
| 04 Jan 2009 11:47 AM |
|
Great! I'll try it first thing tomorrow. You rock Shay! :) |
|
|
|
|
basecoat
 New Member Posts:6

 |
| 05 Jan 2009 12:26 AM |
|
Shait! did'nt work. |
|
|
|
|
basecoat
 New Member Posts:6

 |
| 05 Jan 2009 01:43 AM |
|
I get this error message: + Get-Mailbox -resultsize unlimited | foreach { Set-Mailbox $_.alias -primarySmtpAddress <<<< ("{0}.{1}@mydomain.com" -f $_.firstname,$_.lastname) } Set-Mailbox : Cannot bind parameter 'PrimarySmtpAddress'. Cannot convert value ".@apply.no" to type "Microsoft.Exchange.Data.SmtpAddress". Error: "".@apply.no" is not a valid SMTP address" At line:1 char:87 |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 05 Jan 2009 04:15 AM |
|
Oops.. that's because firstname and lastname are null, they don't exist in Get-Mailbox. Fear not :-), use Get-User to get all 'userMailbox' enabled users and check that their firstname and lastname values are no null. You may also need to turn off emailAddressPolicyEnabled if it is enabled. Finally, remove -whatIf if you find it OK: Get-User -resultSize unlimited -RecipientTypeDetails userMailbox | where {$_.firstname -and $_.lastname} | foreach { Set-Mailbox $_.identity -emailAddressPolicyEnabled:$false -primarySmtpAddress ("{0}.{1}@mydomain.com" -f $_.firstname,$_.lastname) -whatIf }
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
basecoat
 New Member Posts:6

 |
| 05 Jan 2009 05:21 AM |
|
Thanks a whole bunch! I did it manually, but now I really have figured out what powershell can do. I'll be digging deeper into powershell from now on. Thanks again Shay for all your help. :) |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
DavieB
 New Member Posts:1

 |
| 18 Jan 2009 07:00 PM |
|
I need to do the same but don't have exchange 2007, so i'm unable to use get-mailbox. Thoughts? |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
jbright
 New Member Posts:1

 |
| 05 Feb 2009 12:25 PM |
|
Shay... random off topic question. Do you know of a powershell command I could use to search for specific email aliases? I need this to make sure when a user request an alias that it is available and not being used. Thanks,
Josh
jbright@email.wcu.edu |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Phil
 New Member Posts:2

 |
| 24 Feb 2009 02:10 PM |
|
Hi Shay, we are running exchange 2k3. I have never used powershell but I really want to. we need to add an email address to all users in a domain but not be the primary address. I know the ESM can do this with recipient policy. but several hundred users in the domain have custom default addresses that were added after the account was created. so the recipient policy will put their email address back to what the policy is set at. do I basically take out this portion of the command, -primarySmtpAddress. also can you suggest a good book to learn powershell. Thanks, Phil |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 25 Feb 2009 05:48 AM |
|
Basically it would be something like: Get-QADUser sizeLimit 0 -IncludeAllProperties proxyAddresses -ou "ou_dn" | foreach { $proxyAddresses = $_.proxyaddresses+="smtp:newEmail@doamin.com" Set-QADUser $_ -objectAttributes @{proxyAddresses=$proxyAddresses} } I'm using quest AD cmdlets to get the users, you can download it for free, here: http://www.quest.com/powershell/act...erver.aspx My first book recommendation would be: Windows PowerShell In Action. The second is: Windows PowerShell TFM HTH |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
martimart
 New Member Posts:3

 |
| 26 Feb 2009 08:55 AM |
|
Hello Shay,
I am a newbie to the forum. I need to do the same thing as the original post. However, I only have first and lastname of each user in a text file. How can I modify your script to read from a .txt or .csv and then add a new smtp address, not make it the primary, and also clear the "update by policy" check mark.
Thanks,
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 26 Feb 2009 10:48 AM |
|
Create a csv file with three columns: firstname,lastname,newEmail and set the values for each user.
Import-Csv users.csv | foreach { $user = Get-QADUser -firstName $_.firstName -lastName $_.lastName -IncludedProperties proxyAddresses
if($user) { $proxyAddresses = $user.proxyaddresses+="smtp:$($_.newEmail)" Set-QADUser $user -objectAttributes @{proxyAddresses=$proxyAddresses} } }
I need to find out on the "update by policy" option. |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
gwalters13
 New Member Posts:1

 |
| 16 Mar 2009 02:27 PM |
|
Shay, I believe that this is still somewhat on topic... My company has recently split into about 5 separate groups of companies all with different domains. I have updated each Exchange 2007 mailbox with the correct reply to email address, but when I look into my AD the email address that is showing in the General Tab is still the old email address of course. Can help me find a way to update my AD with the default reply to address? I queried this: get-mailbox | export-csv c:\user.csv and have all the data, now I just need help importing to update AD. Thanks in advance for any direction you could provide.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 17 Mar 2009 07:10 AM |
|
To set the default email address: Set-Mailbox userName -PrimarySmtpAddress user@domain.com If the user has a email policy applied then you may have to turn it off: Set-Mailbox userName -PrimarySmtpAddress user@domain.com -EmailAddressPolicyEnabled $false
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
ceasarli
 New Member Posts:12

 |
| 09 Feb 2011 09:16 AM |
|
Shay, I need to ask you a question which encompasses all of the above on this thread. 1. Exchange 2007 2. Mailbox enabled User accounts Question. I need to uncheck recipient policy on all users, set a new external address as primary the smtp address but they must retain the old address as a secondary and lastly this must be read from a txt file or csv file which contains the necessary information. thanks for any help on this matter |
|
|
|
|
fr3dd
 New Member Posts:34

 |
| 09 Feb 2011 11:00 AM |
|
It almost sounds like you are trying to turn the mailboxes into forwarders. If that is the case, there are some switches on the Exchange cmdlets that allow you to set a forwarding address. I believe that when you do this in the GUI it needs to be a receipient that Exchange (AD) has. That would mean that you would need to have contact objects with the external address and associate the contact as the forwarding address on the mailbox. HTH - fr3dd |
|
|
|
|
ceasarli
 New Member Posts:12

 |
| 09 Feb 2011 05:50 PM |
|
No, let me explain some more.. I have two Forest -> Two Exchange Forest Acquisition Forest which was acquired needs to have the @domain.local of the company that bought them so that when reply to address makes it seems like one company even though it is teo separate forests. So, I need 1. Uncheck the recipient policy and keep the account from getting old primary smtp. 2. I need to set the primary smtp using a csv / txt file This part is for some users that I cannot force a stamp of the smtp but make it just a proxy address. 3. I also need to know how to edit the file and prevent the primary smtp and just make the email address an addtional proxyaddress CL |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 10 Feb 2011 01:21 AM |
|
Try this (not tested but should do it), the csv file should have these header: Identity,ExtrenalAddress Import-Csv mailboxUsers.csv | Foreach-Object{ $mbx = Get-Mailbox -Identity $_.Identity $EmailAddresses = $mbx.EmailAddresses += $_.ExtrenalAddress # 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 } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
ceasarli
 New Member Posts:12

 |
| 10 Feb 2011 05:13 AM |
|
Thanks Shay!
But let me ask you the csv file you say it should contain identity,externaladdress
If I understand this correctly the csv file will firstname,lastname,externaladress |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
ceasarli
 New Member Posts:12

 |
| 10 Feb 2011 05:33 AM |
|
I appreciate your time and speedy reply but I am having issues executing this script this is what my environment is Exchange 2007 SVC Pack2, Powershell 1 but I downloaded Powershell 2 not installed yet, I copied the entire script to a txt file labeled it import5.ps1 I run this file from powershell prompt and it seems to run but nothing happens. Did I execute incorrectly? |
|
|
|
|