Created
May 17, 2016 14:14
-
-
Save absolutejam/99e1ff7f84ad07d15fc1c331d98db050 to your computer and use it in GitHub Desktop.
Quick and dirty fix for AD/0365 users who are sending from their onmicrosoft account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ADUser -Filter * ` | |
-SearchBase (Get-ADOrganizationalUnit -Filter 'Name -like "*MY OU*"') ` | |
-Properties ProxyAddresses,Mail | | |
ForEach-Object { | |
if (!($_.Mail)) { | |
Write-Host ($_.SamAccountName + ' - No mail attribute defined') -ForegroundColor Red | |
} else { | |
$NewProxyAddress = ('SMTP:' + $_.Mail) | |
if ($_.ProxyAddresses -notcontains $NewProxyAddress) { | |
Write-Host ($_.SamAccountName + ' - adding entry for ' + $NewProxyAddress) -ForegroundColor green | |
$_.ProxyAddresses.Add($NewProxyAddress) | Out-Null | |
Set-ADUser -Instance $_ | |
} else { | |
Write-Host ($_.SamAccountName + ' - already has entry for ' + $NewProxyAddress) -ForegroundColor Yellow | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment