Hi guys,
I would like to share a great Powershell script that will helps you to cover all users without proxyaddresses on your domain, you can see that I am replacing the GivenName and SurName automatically and updating back the proxyaddresses attribute using Set-ADUser command.
$getsamaccount = Get-ADUser -Filter * -Properties Name, proxyaddresses,mail,enabled,surname,givenname,SamAccountName |
select Name,proxyaddresses,mail,enabled,surname,givenname,SamAccountName | Where-Object {$_.proxyaddresses.count -eq 0 -and $_.enabled -eq 'True' }
foreach ($usersm in $getsamaccount) {
$newsmtp = $usersm.givenname + -join "." + -join $usersm.surname
Set-ADUser $usersm.SamAccountName -Add @{ProxyAddresses="smtp:$news[email protected]","sip:[email protected]"
}
}
You also can run this command to check who doesn’t have any proxyaddresses:
Get-ADUser -Filter * -Properties Name, proxyaddresses,mail,enabled,surname,givenname,SamAccountName |
select Name,proxyaddresses,mail,enabled,surname,givenname,SamAccountName | Where-Object {$_.proxyaddresses.count -eq 0 -and $_.enabled -eq 'True' }
If you want to clear any existing ProxyAddess from CSV file:
#Remove ProxyAddresses from CSV:
$users = Get-Content "C:\Users\MeirP\Desktop\user.txt"
foreach ($us in $users)
{
Set-ADUser $us -Clear ProxyAddresses }