Friday, June 18, 2004

Finding Unused Mailboxes with CDO 1.2

A while ago I posted this script on OutlookExchange that uses Exoledb to find unused mailboxes on a Exchange 2000 server by looking at the unread mail count in the inbox for the last 50 days. Since then I've have a few questions for people wanting to know if they could do this also in Exchange 5.5 mainly to assist in migrations and cleanups. The answer is yes you can but not with Exoledb which is only available on Exchange 2000 and up, what you can use is CDO 1.2 to do something similar.

Another good thing about using CDO 1.2 to do this is you can go a bit further then I did with the simple Exoledb sample by using some of CDO 's cool little built in methods. This is an example of a CDO script that will display the received time of the newest email in the inbox, the sent time of the last mail sent from this mailbox and the unread count for the last 50 days. It logs on to a mailbox using a dynamic profile you supply the alias name as a command line parameter and you need to hardcode the servername in the script.

accountname = WScript.Arguments(0)
set objSession = CreateObject("MAPI.Session")
strProfile = "yourserver" & vbLf & accountname
objSession.Logon "","",False,True,0,True,strProfile
set objFolder1 = objSession.Inbox
set objMsgs1 = objFolder1.Messages
set objMsg1 = objMsgs1.Getlast
set objFolder = objSession.GetDefaultFolder(3)
set objMsgs = objFolder.Messages
set objMsg = objMsgs.Getlast
if objMsg1 is nothing then
wscript.echo "Last Recieved" & "," & accountname & "," & "No Messages"
wscript.echo "Last Recieved" & "," & accountname & "," & objMsg1.TimeSent
end if
if objMsg is nothing then
wscript.echo "Last Sent" & "," & accountname & "," & "No Messages"
wscript.echo "Last Sent" & "," & accountname & "," & objMsg.TimeSent
end if
objFolder1.Messages.Filter.Unread = False
set objMsgFilter = objMsgs1.Filter
objMsgFilter.Unread = True
objMsgFilter.TimeFirst = now()-50
wscript.echo "Number of Unread" & "," & accountname & "," & objMsgs1.count


Anonymous said...

Can this script be modified to work in an Exchange 2003 infrastructure? I have been trying to adjust it to fit my 2k3 environment for weeks and I'm not finding any success.

Glen said...

It will work fine in Exchange 2003 this is where i've used it. I would most probably say if it isn't working you have issue with authentication. By default administrator accounts are specifically denied access to any other account other then their own. If you have a look at this has the steps nessasary to assign an account the rights nessasary to use this script.

If your getting another error what is that error.

Anonymous said...

After reading the suggestions, I reimplemented the securities and I can now successfully use your monad script but it has not cleared the error I see with the script in question. I had previously used delegation and that apparently carries extra permission 'baggage' which causes problems.

The error I'm getting is "Provider: The service has not been started." I've determined that the script is successfully connecting to AD (tried inserting an echo so display the name of the account it is examining and it worked) but failing when the code hits "Rec.Open inbstr"
I've tried rewriting the code to inbstr points to a known good account and I still get the same error. Could there be a problem with the Exchange server?

Glen said...

The script in this post is a VBS CDO script has nothing to do with AD or Exoledb sorry but you've completely lost me. Sounds like you may be trying to use cdoex or exoledb remotly this wont work this is only supported locally on a exchange server. Dont confuse CDO 1.2 with CDOEX they are two different api's that use two different methods to access the Exchange Mailstore

Joe said...

Hi Glenn, I am having a problem with the script as well. I am running it locally on the exchange 2003 server. The error is with Rec.Open inbstr specifically error: object or data matching the name, range, or selection criteria was not found with in the scope of the operation. from the command line I can see the contents of \\.\backstorage\nasa-phx-ex001.nasa.cpwr.corp\mbx
thanks for your help

Glen said...

It looks like you running the script for Outlookexchange ? I would suggest you talk a look at the script in this post which uses CDO 1.2 (or Mapi to be more correct).

To the problem your having it looks like you are using your AD domain ("nasa-phx-ex001.nasa.cpwr.corp") which is not correct for Exoeldb. you need to use you default SMTP email domain from your default recipient policy. (A good way to tell is to look at the properties of the Exchange virtual Directory in Internet Service Manager).


Sean said...

Hi Glen,

I'm also having issues with this script same location as everyone else and im 100% sure the line is correct with my default SMTP address (same address with IIS).

Could you please provide a complete reworked script for Exchange 2003 servers with the CDO 1.2 method you mention?

It would be most appreciated!

Many thanks,


Glen said...

Did you actually read this post ?? this is it


Anonymous said...

One little "gothca" to watch for. If the mailbox is hidden from the address book the MAPI logon will fail with:

"Collaboration Data Objects: The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]]".

Add a check for the attribute msExchHideFromAddressLists=FALSE to avoid this.

Anonymous said...

Can someone explain How I run this script please?
I am in the middle of a 2003 to 2007 tranisition and would like to utilise this script to find accounts that are not being used.

Anonymous said...


Can this script be modified to check the details mentioned with server name, at this point i am running the script successfully with user alias, I need to get data on server level.

Thanks n advance!!

Anonymous said...

i need to pull the same information for users in perticular servers, how can we achive this. we would need to supply server names from csv file or text file. can you let me know the code that would need to be modified here..