none
basic coding: connecting to exchange guide?

    Question

  •  

    I am brand new to Exchange development.

     

    I am looking for a very basic guide on how to connect to an Exchange 2003 and 2007 server, get a list of the servers and storage groups on it, and then get a list of the physical files on the disk that make up those storage groups

     

    Any ideas?

    Monday, July 28, 2008 12:34 AM

All replies

  •  What do you want to write your code in eg VBScript, Powershell or C# there are a few options for doing this if you need to cross both versions then i would suggest you just look at using Straight ADSI (the System.Directoryservices) class in .NET. Because the information you mentioned is all stored in Active Directory you don't really need to use any of the Exchange API's but if you did want to use them you get the same information on Exchange 2007 using the Exchange Mangement Shell cmdlets such as Get-StorageGroup http://technet.microsoft.com/en-us/library/aa998331(EXCHG.80).aspx this would only work on 2007 you would then need to use CDOEXM on Exchange 2003.

     

    As far a guides go there's plenty of on the Internet about using ADSI to do various things just Google ADSI and Exchange. I would also suggest Robbie Allen's Active Directory Cookbook which has quite good coverage of using ADSI.

     

    As a sample here's how you can show the Storage Groups on a server using ADSI in Powershell based on the netbios servername looks like (works on 2003 or 2007)

     

    Code Snippet
     

    $snServerName = "servername"
    $root = [ADSI]'LDAP://RootDSE'
    $cfConfigRootpath = "LDAP://" + $root.ConfigurationNamingContext.tostring()
    $configRoot = [ADSI]$cfConfigRootpath
    $searcher = new-object System.DirectoryServices.DirectorySearcher($configRoot)
    $searcher.Filter = '(&(objectCategory=msExchExchangeServer)(cn=' + $snServerName  + '))'
    $searchres = $searcher.FindOne()
    $snServerEntry = New-Object System.DirectoryServices.directoryentry
    $snServerEntry = $searchres.GetDirectoryEntry()
    $adsiServer = [ADSI]('LDAP://' + $snServerEntry.DistinguishedName)
    $dfsearcher = new-object System.DirectoryServices.DirectorySearcher($adsiServer)
    $dfsearcher.Filter = "(objectCategory=msExchStorageGroup)"
    $srSearchResults = $dfsearcher.FindAll()
    foreach ($srSearchResult in $srSearchResults){
     $sgStorageGroup = New-Object System.DirectoryServices.directoryentry
     $sgStorageGroup =  $srSearchResult.GetDirectoryEntry()
     $sgStorageGroup.Name
     
    }

     

     

     

    Once you get a little better with Powershell you can then do things like this http://gsexdev.blogspot.com/2008/07/show-exchange-whitespace-retained-items.html

     

    Cheers

    Glen

    Monday, July 28, 2008 11:01 PM
  • Umm... ok - I'm confused already!

    I want to use .net 1.1 or .net 2.0.

    I want to build a component that I can put into my app that can connect to an Exchange server, list its storage groups, and get the folders or files on the hard drive that sit behind the storage groups...

     

    I need to be able to do this for Exchange 2k3 and Exchange 2k7.

     

    I don't even know what framework I should be looing at.

     

    Is there an Exchange SDK I can use?

     

    Is there a guide I can refer to?

     

    If I'm going to use ADSI... will that always work?  i.e. there's not always an Active Directory server in place is there?  Like... if I'm working on an SBS 2003 server... that has exchange 2003 built into it... but can I use ADSI in that case?

     

     

    Tuesday, July 29, 2008 5:40 AM
  • If you want to use .NET you can use System.DirectoryServices Namespace to query Active Directory you can do this from either framework.

     

    >If I'm going to use ADSI... will that always work?  i.e. there's not always an Active Directory server in place is there?   >Like... if I'm working on an SBS 2003 server... that has exchange 2003 built into it... but can I use ADSI in that case?

     

      You might want to do a little bit of reading on basic Exchange Architecture before you start trying to tackle writing any code as anything you read in the Exchange SDK and other books is really only going to make sense if you understand the way Exchange and Active Directory interact. Exchange will not function without Active Directory its the configuration and directory store that's critical to the functioning of every Exchange component (more or less). On a SBS server you have AD and Exchange on the same box. System.DirectoryServices Namespace is what you can use in .NET 1.1 and 2.0 to make queries against Active Directory and the Exchange configuration information it stores. To use this namespace sucessfully your also going to have to understand a little bit about LDAP and Active Directory

     

    There are SDK's for both exchange 2003 and 2007 on http://msdn.microsoft.com/exchange you can download. Because of the changes between 2003 and 2007 there isn't a single Exchange API you can use so . Eg you can use CDOEXM in 2003 to list the storage groups on a server (not the file sizes you will still need to use something like WMI or a file provider to do this) but this wont work in 2007. In Exchange 2007 you would need to use the Exchange Management Shell and the Get-StorageGroup cmdlet which you would need to invoke using .NET see http://msdn.microsoft.com/en-us/library/bb332449(EXCHG.80).aspx.  But underlying these are just querying Active Directory which you can do directly using System.DirectoryServices  (or ADSI if you where using a scripting API). That said there maybe somethings you will need to use either of these API's for but for just querying the store file size querying AD is fine (if you where talking about mailbox sizes then that's a different story). The big difference on Exchange 2003 to Exchange 2007 in terms of Store Files is that on Exchange 2007 you only have an EDB store as the STM (stream media file) database was dropped in 2007.

     

    cheers

    Glen

     

     

     

     

    Tuesday, July 29, 2008 6:13 AM
  • You're a rockstar!

    When you say:

     

    "You might want to do a little bit of reading on basic Exchange Architecture before you start trying to tackle writing any code as anything you read in the Exchange SDK and other books is really only going to make sense if you understand the way Exchange and Active Directory interact"

     

    Can you recommend some sites/guides or books that I could read to get a grounding in Exchange architecture and development?

     

     

    Tuesday, July 29, 2008 6:43 AM
  • The Technical reference Guide for 2003 is probably about the best all round document for Exchange http://www.microsoft.com/downloads/thankyou.aspx?familyId=3768246d-c9ed-45d8-bece-a666143cba4e&displayLang=en . The resource center on Technet is also pretty good http://technet.microsoft.com/en-us/library/bb124516(EXCHG.80).aspx  and third party sites like http://www.msexchange.org/ have a lot good articles. There are a number of good books about Exchange although not too many have a broad coverage of development the few that are availible on development are focused on particular subjects. I'd recommend Tony Redmond's book if your looking for a good all round Exchange book (doesn't really cover development)

     

    Cheers

    Glen

     

     

    Tuesday, July 29, 2008 7:18 AM