Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Outlook 2010:Remove TelNo's Programmatically

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
JimPNicholls
Asked:
JimPNicholls
  • 4
  • 3
1 Solution
 
David LeeCommented:
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
 
JimPNichollsAuthor Commented:
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
 
David LeeCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JimPNichollsAuthor Commented:
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
 
David LeeCommented:
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
 
JimPNichollsAuthor Commented:
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
 
David LeeCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now