Search code examples
powershellexchange-serverexchangewebservicesoffice365api

Export Standard/Extended User Greetings (Exchange 2016) - For Use In XMedius AVST


In an earlier post on June 18, 2018 (my birthday BTW), a user asked "Hopefully a simple question - at one time I know when user's recorded their personal greetings for UM voicemail in o365 (regular greeting and/or extended absence greeting) these were stored in their Exchange inbox using a special item type (i.e. "IPM.Configuration.Um.CustomGreetings.External"). However setting up my test o365 setup, getting UM configured and all that, after recording my personal greeting and going through each item starting from the root of my inbox, (some 900+ items - lots of odd stuff in there) - I don't see anything like this any more. Lots of log, activity items, some messages but nothing about greetings. Extracting everything that could cast to an email type to a folder I went through each one - nothing promising. anyone have any clues where the custom greetings for users UM (not auto attendant recordings - that's a different beast) has gone off to and how to get to it?" After reading through the answers as well as the code that was provided by Jeff Lindborg, I thought that I was getting somewhere. With a lot of trial and error, I was finally able to get the EWS-FAI module installed as well as the Exchange Web Services API. Unfortunately, when it came to running the provided code, this is where I am stumped. I'm not a developer or 'coder' in any form, but I'm always looking for effective and efficient methods to do my work. With that said, I'm trying to run this on a Win10 workstation, but can't seem to figure out which program this needs to run within. I've tried Powershell, but that doesn't work. I have access to the necessary accounts for mailbox impersonation as well as any other permissions needed. I've provided the code that was originally supplied for review. Any additional help would be greatly appreciated.

Code

ExchangeService _service;
        _service = new ExchangeService(ExchangeVersion.Exchange2016); // Exchange2013_SP1);
        _service.Credentials = new WebCredentials("user@domain", "myPw");
        _service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

        //select the user you're fetching greetings for
        _service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user@domain");

        //get the root folder for the current account
        var oParamList = new List<FolderId> {WellKnownFolderName.Root};
        var oTemp = _service.BindToFolders(oParamList, PropertySet.FirstClassProperties);
        var oRoot = oTemp.First().Folder;

        var oView = new ItemView(50)
        {
            PropertySet = new PropertySet(BasePropertySet.FirstClassProperties),
            Traversal = ItemTraversal.Associated
        };
        SearchFilter oGreetingFilter = new SearchFilter.ContainsSubstring(ItemSchema.ItemClass,
            "IPM.Configuration.Um.CustomGreetings", ContainmentMode.Substring, ComparisonMode.IgnoreCase);
        var oResults = _service.FindItems(oRoot.Id, oGreetingFilter, oView);

        //fetch the binary for the greetings as values 
        var oPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
        var oRoamingBinary = new ExtendedPropertyDefinition(31753, MapiPropertyType.Binary);
        oPropSet.Add(oRoamingBinary);
        _service.LoadPropertiesForItems(oResults, oPropSet);

        var strFileName = "";
        foreach (var oItem in oResults.Items)
        {
            if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.External",
                StringComparison.InvariantCultureIgnoreCase))
                strFileName = "jlindborg_Standard.wav";
            if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.Oof",
                StringComparison.InvariantCultureIgnoreCase))
                strFileName = "jlindborg_Extended.wav";
            File.WriteAllBytes("d:\\" + strFileName, (byte[]) oItem.ExtendedProperties.First().Value);
        }
    }

Solution

  • The code you posted is c# so you would need to use Visual Studio to create a C# application add a reference to the EWS Managed API and compile that for it to work (you'll need to engage a developer or learn some basic coding).

    EWS-FAI is a powershell module it should be able to return that item and you should be able to write that to a file eg something like

       $MailboxName = "mailbox@domain.com" 
       $Item = Get-FAIItem -MailboxName $MailboxName -ConfigItemName Um.CustomGreetings.External -Folder Inbox -ReturnConfigObject
       [System.IO.File]::WriteAllBytes(("C:\temp\" + $MailboxName + ".wav"),$Item.BinaryData)