Mass Importing Mobile Phone Numbers into Active Directory using PowerShell and QAD Tools.

I had an interesting request at work today.  Management wanted all employees with a company issued cell phone, to have that cell phone number show up in the "Mobile" field of the "Phone/Notes" tab in Outlook.  Due to international legal concerns, it was only to be employees in the US.  

Obviously this information is stored in Active Directory (AD), and Exchange presents it to Outlook via the Global Address List (GAL), so to accomplish this task, I'd need to update the appropriate field in AD.  My first thought was "This should be easy to do with PowerShell, IF someone has a list of names and mobile phone numbers.".   I was in luck, and received a list with almost 7000 names and mobile phone numbers, for all US Employees.  I did a little formatting in Excel, all names in Column A, all Numbers in the appropriate format in Column B, and saved it as a .csv file.

Of course I wasn't going to get off that easy.  The users were spread across multiple domains within our AD forest.  The Set-QADuser command from the QAD Tools snap-in gave an error saying it couldn't resolve a directory object for the given identity.  The command defaults to the domain the account your running the script from is logged into, so the script was giving me this error for every user that was not in the same domain.   To get around this, I had to add a few lines to the script, and use the Get-QADuser command first, then pipe it into the Set-QADuser command.

Here is the final import-mpn.ps1 script:

# Mobile Phone Number Import Script
# By Josh M. Bryant
# https://www.fixtheexchange.com
# Last updated 9/29/11
# Requires Quest ActiveRoles Management Shell for Active Directory (AKA QAD Tools) from: http://www.quest.com/powershell/activeroles-server.aspx
#
# Load QAD tools.
Add-PSSnapin Quest.ActiveRoles.ADManagement
#
# Specificy path to .csv file mapping account name and mobile phone number.
$data = Import-CSV C:\Scripts\cellnumbers.csv
#
# Specify path to log file.
$log = "C:\Scripts\import-mpn.log"
#
# Specify FQDN(s) to search.
$Domains = @(
"domain.com"
"child1.domain.com"
"child2.domain.com"
"child3.domain.com"
)
# Assign Mobile Phone Number to account from .csv
ForEach ($line in $data)
{
$name = $line.Name
$number = $line.Number
$Domains | % {Get-QADUser -Service $_ -Identity $name | Set-QADUser -MobilePhone $number | Out-File -FilePath $log -Append}
}

 

With almost 7000 accounts to process, it took quite some time for the script to complete, but it got the job done. 

As always, if you use or repost this script anywhere, please keep the author information at the top in place, and remember to link back to this site, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *