Skip to content

Instantly share code, notes, and snippets.

@absolutejam
Created May 17, 2016 14:14
Show Gist options
  • Save absolutejam/99e1ff7f84ad07d15fc1c331d98db050 to your computer and use it in GitHub Desktop.
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
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