Forum Discussion
vision311
Jul 03, 2020Copper Contributor
Add Phone Numbers to existing AD Contacts
Dear Community Within the last Days, i had to import ~36000 AD Contacts from Excel. I came from basically zero knowledge and created (copy/paste/edit) following: Contact Import function ...
Erick A. Moreno R.
Jul 08, 2020Iron Contributor
vision311 Hello, Dani.
You can adapt this snippet to your requirements.
$ADContacts = Get-MailContact -ResultSize unlimited -OrganizationalUnit 'Domain.local/Unit1/Unit2/Unit3'
$PhoneNumbers = Import-Csv "C:\Users\emoreno\Desktop\Gal_Export.csv" #Headers: MailAdresses | Telephone | Mobilenumber
Foreach($ToSet in $PhoneNumbers)
{
$ContactMatch? = $null
$ContactMatch? = $ADContacts | Where-Object{$ToSet.MailAdresses -like "*$($_.PrimarySmtpAddress)*" }
If($ContactMatch?)
{
Write-Host "Match found for $($($ContactMatch?.PrimarySmtpAddress).Address)" -ForegroundColor Cyan
Set-Contact -Identity $($ContactMatch?.Identity) -Phone $ToSet.Telephone
Set-Contact -Identity $($ContactMatch?.Identity) -OtherTelephone $ToSet.Mobilenumber
}
Else
{
Write-Host "No Mail Address Match for $($ToSet.MailAddresses)" -ForegroundColor Yellow
}
}
Regards
Erick Moreno