Dean R
(Starting to like KiXtart)
2002-06-06 01:22 PM
Deleting Exchange Mailboxes

Is it possible to delete a mailbox from an exchange 5.5 server using ADSI? or any other method for that matter. I can find no command line tool that will allow me to do it.

Kdyer
(KiX Supporter)
2002-06-06 02:21 PM
Re: Deleting Exchange Mailboxes

Dean,

Doing a quick search, we find..

Deleting a mailbox..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_deleting_a_mailbox.asp

Administrative Tasks..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_recipient_management_tasks.asp

These should be portable to Kix...

Uh.. Wait a sec, these are for Exchange 2000.

OK.. 5.5.

Deleting a mailbox..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ds2x/hh/ds2x/exds_ds2exchgd_40c4.asp

Adminstrative Tasks..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ds2x/hh/ds2x/exds_ds2exchgd_5pgl.asp

HTH,

- Kent


Breaker
(Hey THIS is FUN)
2002-06-06 02:21 PM
Re: Deleting Exchange Mailboxes

Dean,

You could look at this page for an example of how to do this.

And meanwhile - and I know this is well off-topic - are there any Exchange gurus, as well as avid Kixters around here? I have a problem with my Exchange org, connecting to mailboxes across domains. I won't post the details here, but if anyone thinks they might be able to help, or would just like to know the extent of my troubles so they can laugh at me, drop me an email or a private message.

Sorry about that, Dean, not trying to hijack your topic, but you gave me an opportunity to ask my question without actually asking it - cunning, eh?

I've not tried to use ADSI to talk to Exchange, but it should work fine in 5.5 and 2000. I believe Howard Bullock and Chris S have done some work in this area as well.


Dean R
(Starting to like KiXtart)
2002-06-06 02:42 PM
Re: Deleting Exchange Mailboxes

Yes, but I am having trouble writing that into Kix

This is the script, it comes back with an error when it hits "organizationalPerson"
code:
$Object = GetObject ("LDAP://LIMSRVEMAIL1")
$Object.delete "organizationalPerson","cn=tmctest"
$Object.SetInfo
Sleep 5



Chris S.
(MM club member)
2002-06-06 03:00 PM
Re: Deleting Exchange Mailboxes

Dean,

I don't think you've properly defined the container path yet. As a test, you can query the mailbox info for your test account. If you can read the info, then, with the appropriate rights, you should be able to delete it.

Your container path should at least include the following:

quote:
'---------------------------------------------------------------
' Build Recipient container's adsPath:
' LDAP://myserver/CN=Recipients, OU=Site, O=Org
'---------------------------------------------------------------
ADsPath = "LDAP://" + yourserver
ADsPath = ADsPath + "/cn=Recipients,OU="
ADsPath = ADsPath + yourSite
ADsPath = ADsPath + ",O="
ADsPath = ADsPath + yourOrg

After you build your container path, then you can grab the mailbox you want to manipulate:

quote:

Set objCont = GetObject(ADsPath)

'---Create a new MailBox---
Set mailBox = objCont.Create("organizationalPerson", "cn=" & strAlias)

The above sample is a VB example to create an account, changing the "create" to "delete" should (I hope) get the job done. Unfortunately, I can't test this with you as I don't have admin rights on our Exchange server (yet).

edit: 'strAlias' is defined earlier in the script as 'username' which in their example is the UID (or Alias of the Exchange account) and the RDN (NT account associated to the mailbox).

[ 06 June 2002, 15:12: Message edited by: Chris S. ]


Dean R
(Starting to like KiXtart)
2002-06-06 03:11 PM
Re: Deleting Exchange Mailboxes

No, still doesnt work, it gives me a script error still.
It says

code:
OrganizationalPerson Script Error : Unknown Command!  



Chris S.
(MM club member)
2002-06-06 03:20 PM
Re: Deleting Exchange Mailboxes

Can you 'object.get' any of the properties ("cn", "uid", "mail", etc.)?

The examples don't say you have to go though the Assoc-NT-Account route, but if you can see the properties but not delete still then maybe...

[ 06 June 2002, 15:20: Message edited by: Chris S. ]


Dean R
(Starting to like KiXtart)
2002-06-06 03:21 PM
Re: Deleting Exchange Mailboxes

Yes, I can see all those.
.get no problem
.delete wont work
yes I have admin rights to the server


Breaker
(Hey THIS is FUN)
2002-06-06 03:24 PM
Re: Deleting Exchange Mailboxes

Dean,

Try this:

code:
$objCont = GetObject("LDAP://exchangeserver/cn=recipients,ou=sitename,o=org")
if $objcont
? "Bound to LDAP server, Recipients container."
$objcont.delete("organizationalPerson","cn=test")
? "Deleting Test mailbox"
$objcont.setinfo
? "Committing changes to container."
$objcont = 0
goto end
endif

? "Could not bind to LDAP server."

:end
Exit

It works for me on my Exchange 5.5 SP4 box. Hope this helps!


Chris S.
(MM club member)
2002-06-06 03:29 PM
Re: Deleting Exchange Mailboxes

I wonder if it has anything to do with parentheses. I haven't had a lot of luck with Com stuff that doesn't use a ( ) in the object command.

Dean R
(Starting to like KiXtart)
2002-06-06 03:33 PM
Re: Deleting Exchange Mailboxes

5 stars to breaker,
well done me boy.
I now love ADSI and COM objects.

Will try and write a UDF for this one.
[Big Grin] [Big Grin] [Big Grin] [Big Grin] [Roll Eyes] [Smile] [Big Grin]


ShawnAdministrator
(KiX Supporter)
2002-06-06 03:36 PM
Re: Deleting Exchange Mailboxes

yip - nice one - five from me as well.

Chris S.
(MM club member)
2002-06-06 03:38 PM
Re: Deleting Exchange Mailboxes

Well, I'm glad Breaker could help. I quess I didn't add much to the process. [Wink] JK.

I wonder if the .delete is looking for the UID or the RDN? This could make a difference in your script if they don't match.


Breaker
(Hey THIS is FUN)
2002-06-06 04:05 PM
Re: Deleting Exchange Mailboxes

Guys,

For future reference, this link: Click me! should be useful. Exchange 5.5 SDK docs.

Looking forward to the complete set of Exchange admin UDFs, Dean!

[sly...] don't suppose anyone saw my desperate plea for help at the top. Any Exchange genii watching? [Wink]


Chris S.
(MM club member)
2002-06-06 06:16 PM
Re: Deleting Exchange Mailboxes

I just found something that should be looked at. It seems that deleting a mailbox with this method will orphan the store resources. So...besides not only leaving the info hogging up the server's disk space, the next person to get that mailbox name will find their mailbox already populated with someone else's mail!

The M$ method uses DAPI to delete the directory object AND the store.

Reference:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q284199


Breaker
(Hey THIS is FUN)
2002-06-07 09:24 AM
Re: Deleting Exchange Mailboxes

Errr... that looks a bit hardcore to me. Kind of best left to guys who spend all day sitting in darkened rooms... does anyone know if the example at Chris' link would be KiXable?

This link shows an alternate method of deleting multiple mailboxes and other Exchange objects, but it's not really open to scripting unless you want to build the csv file via a script (?). I think I may be stuck trying to go any further - might have to wait for a flash of brilliance from somebody... Chris, Shawn, Millennium Man (Rad!) ??

[time passes slowly when no one has come to work today because of the England game...]

I was just thinking, your best bet if you need to script this operation might be to shell out to the Exchange Admin program, using its /i and /e switches to perform the directory import/export process, and simply editing the csv file in between. I'll try and cobble something together that would do this...

[ 07 June 2002, 10:01: Message edited by: Breaker ]


Dean R
(Starting to like KiXtart)
2002-06-07 09:48 AM
Re: Deleting Exchange Mailboxes

Damn!! (crumples up attempt at UDF)
And I was so happy about that too.
Another alternate method is to install the Admin Service on the Backoffice 4.5 resource kit, and then postie an email to the administration account.
The Admin service places a mailbox on the server that reacts to emails and creates and/or deletes mailboxes.
Havent tested it yet as the f$#%in thing wont install for me.
[Mad]


Dean R
(Starting to like KiXtart)
2002-06-12 10:57 AM
Re: Deleting Exchange Mailboxes

BUMP

Did you see any reference to problems creating a mailbox using ADSI in 5.5?
I couldnt find any, so the whole UDF thingymibob might still be worth writing, but in reverse, create instead of delete.
Will look into it.
God I want Exchange 2000, damn micro$oft and their Active Directory.
Actually I should say, damn the transmitter manufacturers and their inability to update their software to work with it. [Big Grin]

P.S- Anyone here use the Admin Agent for Exchange 5.5?, still cant get the damn thing working.

[ 12 June 2002, 10:59: Message edited by: Dean R ]


Chris S.
(MM club member)
2002-06-12 01:02 PM
Re: Deleting Exchange Mailboxes

No problems creating mailboxes at all. I think KiX would be very good at it, in fact.

BrianTX
(Korg Regular)
2002-06-12 10:28 PM
Re: Deleting Exchange Mailboxes

Does this ADSI stuff work if you don't have the LDAP setup on your network?

I have an interesting problem:

Some users NEVER log on to our network but get email via pop3, so it is very difficult to figure out what accounts are active or not. (I don't make the policy!!!) This is compounded by the fact that McAfee GroupShield runs on our exchange server and logs in every couple of weeks when we run an "on-demand" scan of all our mailboxes, so it shows the last logon as being the McAfee and not the user... so.. does anyone have a solution for finding out which users have been active within the last 60 days, even though they do not always log in through our domain controllers?

Brian


Chris S.
(MM club member)
2002-06-12 11:00 PM
Re: Deleting Exchange Mailboxes

Yes, you can make LDAP calls against Exchange even without an LDAP server setup. According to my companies network guys, we don't have an LDAP in production and my LDAP-based queries ran fine.

**DONOTDELETE**
(Lurker)
2002-06-21 04:22 PM
Re: Deleting Exchange Mailboxes

Brian,

Even if the users are using POP3 to access their mailbox they should register an authentication request against a DC (albeit via the exchange server). You should be able to query the LastLogin property of a user account via the WinNT: provider (or the LDAP one if you are lucky enough to have an AD - we are still in the dark ages here). I have some code that will do this if you think it might work for you...

Michael.