vrijdag 22 maart 2013

Exchange 2007: Powershell - Change user's reply address



I need to change the reply(primary) address of all users in a specific OU.

 
In this article a powershell script that gets the job done.




This script needs to be run in the Exchange Management Shell, probably installed on the Exchange 2007 server. You can download it from the next location:
http://www.microsoft.com/en-us/download/details.aspx?id=11876

#specify a domain controller to work with
$dc =
#Create an output file to capture the results
$Output = "c:\output.txt"
Out-File $Output -InputObject "OldPrimarySMTPAddress`tNewPrimarySMTPAddress"
#specify the OU you wish to pull the users from
$OU = "domain.com/Users" #replace with the OU you want to work with
#specify the domain of the new SMTP address you want to change it to
$NewDomain = "NDomain.com"
#get a list of all mailboxes in the OU
$list = get-mailbox -OrganizationalUnit $OU -resultsize Unlimited -DomainController $DC
#Iterate through the list
foreach ($user in $list)
{
$mb = Get-mailbox $user -DomainController $dc
#capture current primary smtp address
$SMTP = $mb.PrimarySmtpAddress
[string]$Local = $SMTP.Local
[string]$OldDomain = $SMTP.Domain
[string]$CPSMTP = $Local + "@" + $OldDomain
#captur new primary smtp address
[string]$NPSMTP = $Local + "@" + $NewDomain
#capture the old and the new SMTP addresses to the output file
[string]$iobject = $CPSMTP + "`t" + $NPSMTP
Out-File $Output -InputObject $iobject -Append
#set the new primary smtp address on the mailbox and remove the flag to use the email address policy (if you do not do this, the email address will revert to whatever the policy has set to)
Set-Mailbox $user -PrimarySmtpAddress $NPSMTP -EmailAddressPolicyEnabled $false -DomainController $DC
}
 


There are a few variables that needs to be changed:
$dc, your Domain Controller
$OU, The OU the user's reside
$NewDomain, The new primary mail domain that will replace the old one

Change them and after a run the script saved you lots of time :) Till next time!!
 
 

Geen opmerkingen:

Een reactie posten