Getting a list of mailboxes with WebDAV

OK, WebDAV does not have the ability itself to get a list of mailboxes. However you can use other APIs and even use an OWA call to get a list of mailboxes.

Reading the GAL:

WebDAV itself cannot do this. You could use the OWA GALFIND command, which has some limited ability. You could also use ADSI, CDO 1.21 or Extended MAPI as long as you’re running in-network. There is no Exchange Web Service (EWS) call for doing this (at least not in Exchange 2007 SP1)).

GALFIND:

GALFIND is an OWA call which is supported to use. It is not a WebDAV call. Basically, you do a GET against a URL and pass it search parameters.

Format of the OWA call:

sServerURL = "https://"+ sServerURL + "/public/?Cmd=galfind

Information on the unsupported call is covered in the following article:

Customizing Microsoft Outlook Web Access

https://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6532E454-073E-4974-A800-1490A7CB358F

Basic call - use the following URI and choose "GET - OWA Call" - you will not need a body, all info past to OWA are in the uri:

https://<Exchange server>/exchange/?cmd=galfind

Here are the possible search Parameters:

 

      DN Display Name ex: Robert Jones

      FN First Name ex: Robert

      LN Last Name ex: Jones

      TL Title ex: Big Manager

AN Alias ex: bobj

      CP Company ex: microsoft

      DP Department ex: Exchange

      OF Office ex: Bld 15/2124

      CY        City ex: Redmond

 

Note: There is no ability to search against other fields such as phone number, etc.

 

Example URIs:

https://myexserver/public/?Cmd=galfind&an=bobj

https://myexserver/exchange/administrator/Inbox/?cmd=galfind&an=a

https://myexserver/exchange/administrator/Inbox/?cmd=galfind&cp=microsoft

Example Raw Request:

GET - OWA Call https://myexchangeserver/exchange/myuser/?cmd=galfind HTTP/1.1

Pragma: no-cache

Content-Type: text/xml

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)

Here are the supported methods:

CDO 1.21:

How To Work with Distribution Lists Using CDO (1.x) from Visual Basic

https://support.microsoft.com/?id=178787

ADSI:

241474 HOWTO: Render the Global Address List with ADSI

https://support.microsoft.com/?id=241474

Extended MAPI:

166106 HOWTO: Getting the Contents of the Exchange Global Address List

https://support.microsoft.com/?id=166106

More on using Extended MAPI to read the Mailbox Table:

The Mailbox Table in Exchange holds a list of Mailboxes and related mailbox information. Reading this table can only be done with Extended MAPI or WMI can be used on an Exchange 2003 server.

Extended MAPI can be used with Exchange 5.5 and later.

XCLN: How to Retrieve Last Logon Time of Exchange Users Using Extended MAPI

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

How to loop through mailboxes on Exchange by using the GetMailboxTable method

https://support.microsoft.com/kb/200160/

With Exchange 2003 and later, you can use WMI:

LastLogonTime Property

https://msdn.microsoft.com/en-us/library/aa144762.aspx

Here is a sample of using GALFIND:

' GALFIND Sample

' GALFIND will return results which can be consumed by your application as xml.

' You can test the URL by putting it into IE and seeing the results.

' TODO: Have Basic Authentication turned ON on the virtual directory for the item and no anonymous.

' Note: there is no Translate header set for a GET against an OWA URL – That’s because we are not using WebDAV, we are using the results from an OWA page.

sub ReadFileText (sFile)

    Dim objFSO 'As FileSystemObject

    dim oTS

    dim sText

   

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set oTS = objFSO.OpenTextFile(sFile)

    sText = oTS.ReadAll

    oTS.close

    set oTS = nothing

    Set objFSO = nothing

 

    ReadFileText = sText

    

end sub

Private Sub WriteFileText(sFilePath, sText)

    Dim objFSO 'As FileSystemObject

    Dim objTextFile 'As Object

   

    Const ForReading = 1

    Const ForWriting = 2

    Const ForAppending = 8

   

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objTextFile = objFSO.CreateTextFile(sFilePath, True)

   

    ' Write a line.

    objTextFile.Write (sText)

    objTextFile.Close

    'objTextFile.Close

End Sub

 

dim sHREF

dim sUserName

dim sPassword

dim sResponse

Dim HttpWebRequest

 

shref="https://myexchangeserver.company.com/exchange/?cmd=galfind&DN=bobbie" mce_href="https://myexchangeserver.company.com/exchange/?cmd=galfind&DN=bobbie" ' TODO: change

 

sUserName = "Administrator" ' TODO: change

sPassword = "" ' TODO: change

set HttpWebRequest = CreateObject("microsoft.xmlhttp")

 

if sPassword = "" then

    HttpWebRequest.Open "GET", sHREF , False

else

    HttpWebRequest.Open "GET", sHREF , False, sUserName, sPassword

end if

HttpWebRequest.Send

sResponse = HttpWebRequest.ResponseText ' Returns as text

Set HttpWebRequest = Nothing

wscript.echo sResponse