none
Set-UserPhoto via EWS RRS feed

  • Question

  • Hi All,

    I am doing some research for a project I have which requires that I provide a mechanism to allow staff to update User Photos in Active Directory and Exchange 2013.

    I currently have a WinForms application that allows staff to update their personal details and this already includes the ability to show / remove their photo in Active Directory. I have been asked to look at using higher resolution images available when the image is stored in Exchange.

    I note that their is a Set-UserPhoto PowerShell CmdLet that can set both AD and Exchange images. What I was trying to find out is if there is a method to do the same via VB.NET. I still cannot seem to find any methods available via Exchange Web Services or the EWA managed API other than "GetUserPhoto" method.

    Any help would great,

    Thanks.

    Nathan Sutton


    NSutton

    Sunday, October 9, 2016 7:56 AM

Answers

  • In Exchange Online/2016 there is a SetUserPhoto operation you can use (not in the Managed API though) eg the following working in O365

                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2016;
                String EWSURI = "https://outlook.office365.com/ews/exchange.asmx";
                esb.Url =  EWSURI;
                esb.Credentials = new NetworkCredential("user@domain.com", "pass");
                esb.CookieContainer = new CookieContainer();
                SetUserPhotoType spSetPhoto = new SetUserPhotoType();
                spSetPhoto.Email = "user@domain.com";
                spSetPhoto.TypeRequested = new UserPhotoTypeType();
                spSetPhoto.TypeRequestedSpecified = true;
                spSetPhoto.TypeRequested = UserPhotoTypeType.UserPhoto;
                Byte[] FileContent = File.ReadAllBytes(@"c:\temp\20141103_152624.jpg");
                spSetPhoto.Content = Convert.ToBase64String(FileContent);
                SetUserPhotoResponseMessageType setUserRespon =  esb.SetUserPhoto(spSetPhoto);

    but as stated in the documentation https://msdn.microsoft.com/en-us/library/mt552422(v=exchg.80).aspx its not available in 2007,2010,2013. At a raw level its creating an object in the Root of mailbox which could also be done in a unsupported method in EWS but (I've not seen anybody attempt it)  I would probably suggest the following.

    You should be able to use Set-UserPhoto via remote Powershell in your vb.net code eg https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.140).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 there are VB.net sample in that code. There are some security issues with that method (eg using a service account to do the updates etc) but if you create your own backend WebService you should be able to address most objections people might have.

    • Marked as answer by Nathan Sutton Tuesday, October 18, 2016 12:01 AM
    Monday, October 10, 2016 3:36 AM

All replies

  • In Exchange Online/2016 there is a SetUserPhoto operation you can use (not in the Managed API though) eg the following working in O365

                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2016;
                String EWSURI = "https://outlook.office365.com/ews/exchange.asmx";
                esb.Url =  EWSURI;
                esb.Credentials = new NetworkCredential("user@domain.com", "pass");
                esb.CookieContainer = new CookieContainer();
                SetUserPhotoType spSetPhoto = new SetUserPhotoType();
                spSetPhoto.Email = "user@domain.com";
                spSetPhoto.TypeRequested = new UserPhotoTypeType();
                spSetPhoto.TypeRequestedSpecified = true;
                spSetPhoto.TypeRequested = UserPhotoTypeType.UserPhoto;
                Byte[] FileContent = File.ReadAllBytes(@"c:\temp\20141103_152624.jpg");
                spSetPhoto.Content = Convert.ToBase64String(FileContent);
                SetUserPhotoResponseMessageType setUserRespon =  esb.SetUserPhoto(spSetPhoto);

    but as stated in the documentation https://msdn.microsoft.com/en-us/library/mt552422(v=exchg.80).aspx its not available in 2007,2010,2013. At a raw level its creating an object in the Root of mailbox which could also be done in a unsupported method in EWS but (I've not seen anybody attempt it)  I would probably suggest the following.

    You should be able to use Set-UserPhoto via remote Powershell in your vb.net code eg https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.140).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 there are VB.net sample in that code. There are some security issues with that method (eg using a service account to do the updates etc) but if you create your own backend WebService you should be able to address most objections people might have.

    • Marked as answer by Nathan Sutton Tuesday, October 18, 2016 12:01 AM
    Monday, October 10, 2016 3:36 AM
  • Hi Glen,

    Sorry for the delay and thanks for the response.

    I will definitely check out the Exchange Cmdlets option as the WinForms application I have already has its own Web Service for all of the calls to AD and SQL servers. Hopefully this will plug the hole I have.

    Thanks again.


    NSutton

    Tuesday, October 18, 2016 12:01 AM