Page 1 of 1 1
Topic Options
#189134 - 2008-08-16 06:58 AM Deleting Outlook Distribution Lists
jeremyschubert Offline
Getting the hang of it

Registered: 2005-09-17
Posts: 89
At http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul07/hey0731.mspx I found a vbscript that will create a new Outlook Distribution list based on active directory group membership. Problem is, if I want to run the script a second time, for example daily through users logon script, it just creates a second distribution list (with the member list modified) but the same name as the original. And I can't seem to find any scripts I can use to delete an existing Outlook distribution list (I did a quick search in the UDF library). Has anyone ever seen a kix script used to delete an Outlook distribution list?
Thanks,
Jeremy
_________________________
---
Bishop Grandin Technology Department
'Either we're on time, or we're late'

Top
#189135 - 2008-08-16 07:57 AM Re: Deleting Outlook Distribution Lists [Re: jeremyschubert]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
I haven't had much luck finding anything for you, but if there was a place to search it would be http://www.outlookcode.com. Seems like to me you don't really have to delete the DL, but just update it. I did find an article describing how to delete all the members.

http://www.outlookcode.com/codedetail.aspx?id=235

Then you could just re-ad the users?

I can see some use for this in an envirnoment I work for, so if you can find anything, I'll be glad to help as much as I can.
_________________________
(... better days ahead)

Top
#189136 - 2008-08-16 07:30 PM Re: Deleting Outlook Distribution Lists [Re: Allen]
jeremyschubert Offline
Getting the hang of it

Registered: 2005-09-17
Posts: 89
Thanks Allen, what you say makes a lot of sense. I've decided I'm going to write two scripts. The first one will just create the distribution lists. I'll run that by a RunOnce GPO. Then, I'll use the second script (from GPO or call from logon script) as necessary. That script will remove the existing members of the distribution list and then re populate it.
It will probably be vbscript. If I post the code here, will you help translate it to kix for those who want to use kid?
Jeremy
_________________________
---
Bishop Grandin Technology Department
'Either we're on time, or we're late'

Top
#189137 - 2008-08-16 08:34 PM Re: Deleting Outlook Distribution Lists [Re: jeremyschubert]
jeremyschubert Offline
Getting the hang of it

Registered: 2005-09-17
Posts: 89
Allen, I threw this vbscript together quickly and haven't tested it yet. Could you please look at it and see if it could easily be translated to Kix?

Script 1 - Run Once To Create Distribution Lists
 Code:
On Error Resume Next

Const olDistributionListItem = 7

Set objOutlook = CreateObject("Outlook.Application")
Set objList = objOutlook.CreateItem(olDistributionListItem )

objList.DLName = Math Teachers"
objList.Save

Set objGroup = GetObject("LDAP://[enter appropriate path here]CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

For Each strUser in objGroup.Member
    Set objUser = GetObject("LDAP://" & strUser)
    strUserName = objUser.displayName

    Set objRecipient = objOutlook.Session.CreateRecipient(strUserName)
    objRecipient.Resolve
    objList.AddMember objRecipient
Next

Set objOutlook = CreateObject("Outlook.Application")
Set objList = objOutlook.CreateItem(olDistributionListItem )

objList.DLName = English Teachers"
objList.Save

Set objGroup = GetObject("LDAP://[enter appropriate path here]CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

For Each strUser in objGroup.Member
    Set objUser = GetObject("LDAP://" & strUser)
    strUserName = objUser.displayName

    Set objRecipient = objOutlook.Session.CreateRecipient(strUserName)
    objRecipient.Resolve
    objList.AddMember objRecipient
Next

wscript.quit


And this code is to later on revise the distribution lists:

 Code:
On Error Resume Next

Const olDistributionListItem  = 10

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

 Dim i As Integer
    Dim objRecip As Outlook.Recipient
    For i = objDL.MemberCount To 1 Step -1
        Set objRecip = objDL.GetMember(i)
        objDL.RemoveMember objRecip
    Next
    MsgBox objDL.MemberCount
    Set objRecip = Nothing

Set objList = objFolder.Items("Math Teachers")

Set objGroup = GetObject("LDAP://[fill in your path here]CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

For Each strUser in objGroup.Member
    Set objUser = GetObject("LDAP://" & strUser)
    strUserName = objUser.displayName

    Set objRecipient = objOutlook.Session.CreateRecipient(strUserName)
    objRecipient.Resolve
    objList.AddMember objRecipient
Next

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

 Dim i As Integer
    Dim objRecip As Outlook.Recipient
    For i = objDL.MemberCount To 1 Step -1
        Set objRecip = objDL.GetMember(i)
        objDL.RemoveMember objRecip
    Next
    MsgBox objDL.MemberCount
    Set objRecip = Nothing

Set objList = objFolder.Items("Science Teachers")

Set objGroup = GetObject("LDAP://[fill in your path here]CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

For Each strUser in objGroup.Member
    Set objUser = GetObject("LDAP://" & strUser)
    strUserName = objUser.displayName

    Set objRecipient = objOutlook.Session.CreateRecipient(strUserName)
    objRecipient.Resolve
    objList.AddMember objRecipient
Next

wscript.quit


Edited by jeremyschubert (2008-08-16 09:07 PM)
_________________________
---
Bishop Grandin Technology Department
'Either we're on time, or we're late'

Top
#189138 - 2008-08-16 10:05 PM Re: Deleting Outlook Distribution Lists [Re: jeremyschubert]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Conversion shouldn't be to bad.

I'm going to be tied up most of the afternoon. So it may be a while before I can look at it.
_________________________
(... better days ahead)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.055 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org