VBScript: Clean Up Imported SIM Card Contacts in Outlook

The other day, I was texting a friend and some guy looked at me and said “Oh hey, 2002 called, it wants its T9 back.” Haha, slightly cliche but I laughed anyway. Then I went and bought myself a Blackberry.

I totally love it, I won’t lie. So I imported my contacts into Outlook from a Sony Ericsson mobile phone and they came out kinda chu-chu. All the contacts came in as “Work” numbers and were all prefixed by “;\M”. I cleaned the M’s out manually but then wrote a script to list all the numbers as Mobile numbers. For consistency’s sake, I also cleaned up all of the numbers themselves to just be, for instance, 2345551212. Here’s the script in case you would like to do a mass cleanse as well.

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")

Set colContacts = objNamespace.GetDefaultFolder(10).Items ' 10 = olFolderContacts

For Each objContact In colContacts
if len(objContact.MobileTelephoneNumber) = 0 then
objContact.MobileTelephoneNumber = objContact.BusinessTelephoneNumber
objContact.BusinessTelephoneNumber = ""
'Wscript.Echo objContact.FullName, objContact.BusinessTelephoneNumber, objContact.MobileTelephoneNumber
objContact.Save
end if

if len(objContact.MobileTelephoneNumber) > 0 then
mobileNumber = objContact.MobileTelephoneNumber
mobileNumber = replace(mobileNumber," ","")
mobileNumber = replace(mobileNumber,"-","")
mobileNumber = replace(mobileNumber,"(","")
mobileNumber = replace(mobileNumber,")","")
mobileNumber = replace(mobileNumber,"+1","")

if left(mobileNumber,1) = "1" then mobileNumber = right(mobileNumber,len(mobileNumber)-1)
objContact.MobileTelephoneNumber = mobileNumber
objContact.Save
End if

Next

Ouu my grammar has gone downhill since I spent a weekend in Louisiana.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in VBScript
4 comments on “VBScript: Clean Up Imported SIM Card Contacts in Outlook
  1. bryan says:

    thank you!!

  2. Omer says:

    Thanks for this helpful code :)

    Omer KARADENIZ
    http://www.omerkaradeniz.com

  3. Pretty cool script.

    “if left(mobileNumber,1) = “1” then mobileNumber = right(mobileNumber,len(mobileNumber)-1)”

    Using mid(mobileNumber,2) would be cleaner. That’s nit-picking though.
    sorry. ;-)

    I like your website by the way. I’m book-marking it right now.

  4. Chrissy says:

    Very true! I totally forgot about mid(). Thanks Patrick.

Leave a Reply

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

*