Solved

Outlook 2010:Remove TelNo's Programmatically

Posted on 2013-06-18
7
223 Views
Last Modified: 2014-06-27
Outlook 2010 Exchange 2010

I have an issue where personal mobiles were added to Outlook contacts during a recent Lync 2010 rollout (The personal numbers were in the IPPhone field in AD which should have been hidden from the users but when adding a LYNC contact, pulled this info into Outlook).

Long story short, I need a script which binds all contact numbers together and then delete the offending numbers but not the contact. I haven't a clue where to start so any pointers would be much appreciated.
0
Comment
Question by:JimPNicholls
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39257272
Hi, JimPNicholls.

I can provide a script that will delete the numbers from Outlook contacts, but to do that I need to know which contact field the numbers are in.
0
 

Author Comment

by:JimPNicholls
ID: 39257547
Hi BlueDevilFan,

The field this has mapped into is objContact.MobileTelephoneNumber. I have approx 300 possible numbers so I'm just looking for a efficient way to remove them in one hit.

Regards.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39258872
The script below will delete the value of the MobileTelephoneNumber property on ALL contacts in your default contacts folder.  Please note that the script will delete all mobile numbers including those that did not come from the Lync rollout.

To use it

1.  Open Notepad
2.  Copy the code and paste it into Notepad
3.  Save the file.  You can name it anything you want, but the file extension must be .vbs
4.  Double-click the file to run the script

If anyone else needs to run the script also, then you can place it on a file share they have access to and send them a link pointing to the script.

Const olFolderContacts = 10
Const olContact = 40
Dim olkApp, olkSes, olkFld, olkCon
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName
Set olkFld = olkSes.GetDefaultFolder(olFolderContacts)
For Each olkCon In olkFld.Items
    If olkCon.Class = olContact Then
        olkCon.MobileTelephoneNumber = ""
        olkCon.Save
    End If
Next
olkSes.Logoff
Set olkCon = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
MsgBox "The mobile number on all contacts has been deleted.", vbInformation + vbOKOnly, "Delete Mobile Numbers"

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:JimPNicholls
ID: 39259154
Thanks for this. This could work but I don't want to delete all mobile numbers. If I have a txt file listing all numbers, is it possible to effectively loop through each number per contact and if it matches, delete it?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39259412
Yes, that's possible.  Is it one number per line in the text file?  Are the numbers in the text file formatted the same way as they are in Outlook (e.g. (xxx) yyy-zzz)?
0
 

Author Comment

by:JimPNicholls
ID: 39259799
If dabbled and come up with the following. I think this'll work and thanks everso for pointing me in the right direction.

Const olFolderContacts = 10
Const olContact = 40
Const ForReading = 1

Dim olkApp, olkSes, olkFld, olkCon
Dim arrFileLines()

Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\IPPhone Numbers.txt", ForReading)

'Open the txt file and bind numbers
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close

olkSes.Logon olkApp.DefaultProfileName
Set olkFld = olkSes.GetDefaultFolder(olFolderContacts)
For Each olkCon In olkFld.Items
    If olkCon.Class = olContact Then
          For Each strLine in arrFileLines
                  If olkCon.MobileTelephoneNumber = strLine Then
              'olkCon.MobileTelephoneNumber = ""
              'olkCon.Save
              WScript.Echo "Match"
              End If
                  WScript.Echo strLine & " " & olkCon.MobileTelephoneNumber

            Next
End If


Next
olkSes.Logoff
Set olkCon = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
MsgBox "The mobile number on all contacts has been deleted.", vbInformation + vbOKOnly, "Delete Mobile Numbers"
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39259873
You're welcome.  

I had a slightly different, perhaps faster, solution in mind, but it looks like this will work so long as the numbers in the file are formatted the same way the numbers in Outlook are.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now