I've recently had to replace the Primary SMTP address for all users within an organisation. Of course this is a lot easier if you script it.
I needed to do this as the client was changing their primary address, but wanted to retain all the current proxyAddresses as well.
This was achieved by using two scripts.
$Users = Get-ADUser -SearchBase 'OU=ouname,OU=ouname,OU=ouname,OU=ouname,DC=domai,DC=com,DC=au' -Filter * -Properties mail,ProxyAddresses | Select-Object samaccountname,ProxyAddresses
Foreach ($User in $Users)
{
$Samaccountname = $User.samaccountname
$SMTP = "SMTP:$samaccountname@newdomain.com.au"
Set-ADUser $samaccountname -Add @{proxyAddresses=$SMTP}
}
This script adds the new SMTP address for all users within a certain OU. Of course this will cause some troubles on its own, as there's now going to be two SMTP addresses, marked as primary.
The following script clears this up:
Get-ADUser -SearchBase 'OU=ouname,OU=ouname,OU=ouname,OU=ouname,DC=domai,DC=com,DC=au' -Filter * -Properties mail,ProxyAddresses |
Foreach {
$proxies = $_.ProxyAddresses |
ForEach-Object{
$a = $_ -replace 'SMTP','smtp'
if($a -match 'newdomain.com.au'){
$a -replace 'smtp','SMTP'
}else{
$a
}
}
$_.ProxyAddresse = $proxies
Set-ADUser -instance $_
}
This will remove smtp:firstname.lastname@domain.com and replace it with SMTP:firstname.lastname@domain.com
ReplyDelete[string]$proxydomain = "@Domain.com.au"; #Proxy domain
[string]$usersOU = "OU=Users,DC=Domain,DC=local"; #OU to apply changes
[int]$count = 0 ;
Import-Module ActiveDirectory
Get-ADUser -Filter "*" -SearchScope Subtree -SearchBase "$usersOU" -Properties proxyAddresses, employeeType, givenName, Surname | foreach-object {
Write-Host "Editing user: $_.SamAccountName"
if ($_.Proxyaddresses -match $_.givenName+"."+$_.Surname+$proxydomain)
{
Set-ADUser -Identity $_.SamAccountName -remove @{proxyAddresses="smtp:"+$_.givenName+"."+$_.Surname+$proxydomain}
Write-Host "Removed '$_.SamAccountName' smtp Address"
Set-ADUser -Identity $_.SamAccountName -add @{proxyAddresses="SMTP:"+$_.givenName+"."+$_.Surname+$proxydomain}
Write-Host "Result: Added '$_.SamAccountName' Proxy address."
$count++
}
else
{
Write-Host "Nothing Changed."
}
}
Write-Host "Sucessfully Edited" $count "users"
Great, that has done it for me!
DeleteThank you
end of lease cleaning sydney
ReplyDeleteThis is good step because many new users were facing issues during replacing their script, but now they are happy because with the help of this content, they can solve their issues easily. Coursework writing services.
ReplyDeleteYou have shared a very nice post but to be honest, I do not have enough time to complete it because I have to find a Research Article Writer for Publication of my article. Although, I would feel great to complete it first, but I have to find a writer on a very urgent basis.
ReplyDeletegoogle 218
ReplyDeletegoogle 219
google 220
google 221
ReplyDeletehttp://94.237.75.108/
Jupiter Solar
ReplyDeleteAbout Jupiter Solar
Glass lined solar water heater
Ceramic Coated Solar Water Heater
Stainless Steel Solar Water Heater
Copper Tank solar water heater
solar water heater Frequently Asked Questions Jupiter Solar
Contact us Jupiter Solar
This comment has been removed by the author.
ReplyDeleteThe principal Simple Mail Transfer Protocol (SMTP) address of an account to be used for server-to-server authorisation or delegation access is represented by the PrimarySmtpAddress element.https://webdesignslash.com.au/video-animation-services/
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteCmolds stands among the top app design companies, crafting innovative and tailored solutions that redefine user experiences and drive business growth. Elevate your app vision with Cmolds' expert design expertise and create unforgettable digital journeys.
ReplyDelete
ReplyDeletehigere7173@arensus.com