/build/static/layout/Breadcrumb_cap_w.png

bulk adding smtp address to ad users that don't have the address

The intermediate files are handy, save them and set aside. If you screw up, you'll know what users to go back and fix!



get-aduser -filter * -SearchBase "OU=WHATOU,DC=DOMAIN,DC=DOMAIN" -properties * | where {$_.distinguishedname -notlike "*OUyouDONTwant*" -and $_.distinguishedname -notlike "*UnwantedOU*"} | Where {$_.emailaddress}| where {$_.emailaddress -notlike "*UnwantedSuffix*"} |Where {$_.proxyAddresses} | Where {-not($_.proxyAddresses  -like "*NewProxyAddress*")} | select-object samaccountname | Export-Csv c:\scripts\NO_NewSuffix.csv -NoTypeInformation

 

get-content c:\scripts\NO_NewSuffix.csv | select-string -pattern 'SamAccountName' -notmatch | % {$_ -replace '"', ""} | out-file c:\scripts\NO_NewSuffix_C.txt

 

$noNewSuffix = Get-Content c:\scripts\NO_NewSuffix_C.txt

 

foreach($user in $noNewSuffix)

{

$client = get-aduser "$user" -properties *

$emailP = $client.emailaddress

write-host "Email: $emailP" ##output to confirm whats happening

$newproxy = $emailP -replace '@OLD.SUFFIX','@NEW.SUFFIX'

write-host "NewProxy: $newproxy" 

##output to confirm whats happening

$NP=[string]::concat("smtp:",$newproxy)

write-host "Appended with smtp: $NP" ##output to confirm whats happening

##runfirst without set once confirmed uncomment set ## set-aduser -identity "$user" -add @{proxyaddresses="$NP"}


Comments

This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ