Set-UserPhoto doesn't work with CBA flow in EXO V2 module

Hans Hedman 56 Reputation points
2020-09-17T12:36:24.117+00:00

We have an Exchange hybrid organisation where all users are migrated to Exchange online. I have been using a script to update user photos in the local AD but because of the limitations with Azure AD Connect, I'd like to script the upload of photos to Exchange Online.

Since basic authentication isn't going to be supported for much longer I'd like to use modern authentication using the Exchange Online PowerShell V2 module that supports MFA and app-only authentication.

I have followed the guide on Docs on how to register an App in Azure AD and to be sure that there isn't a rights issue I have given the App the role of Global Administrator.

But I get an error message when trying to set the user photo.
These are the commands I use (sensitive data replaced with xxx):

Connect-ExchangeOnline -CertificateThumbPrint “xxxxxx” -AppID “xxx-xxx-xxx-xxx-xxxx” -Organization “myorg.onmicrosoft.com” -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxyMethod=RPS
Set-UserPhoto -Identity hanstest -PictureData ([System.IO.File]::ReadAllBytes("C:\Install\be2.jpg")) -Confirm:$false

Which results in the following response:

Error on proxy command 'Set-UserPhoto -Identity:'hanstest' -PictureData:'255','216' ... ,'217' -Confirm:$False' to server AM6PR05MB5523.eurprd05.prod.outlook.com: Server version 15.20.337
0.0000, Proxy method RPS:
Connecting to remote server am6pr05mb5523.eurprd05.prod.outlook.com failed with the following error message : ば鸣˅ For more information, see the about
_Remote_Troubleshooting Help topic. [Server=DB8PR05MB6745,RequestId=311495a1-a0c5-4e8e-ba54-b8e539667afb,TimeStamp=2020-09-17 10:08:53] .
    + CategoryInfo          : NotSpecified: (:) [Set-UserPhoto], CmdletProxyException
    + FullyQualifiedErrorId : [Server=DB8PR05MB6745,RequestId=311495a1-a0c5-4e8e-ba54-b8e539667afb,TimeStamp=2020-09-17 10:08:53] [FailureCategory=C
   mdlet-CmdletProxyException] B833102,Microsoft.Exchange.Management.RecipientTasks.SetUserPhoto
    + PSComputerName        : outlook.office365.com

To confirm that there's nothing wrong with the actual photo and command syntax I have tried with basic authentication and that works. Here are the commands I use for that:

$Credential = Get-Credential
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxyMethod=RPS -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $ExSession
Set-UserPhoto -Identity hanstest -PictureData ([System.IO.File]::ReadAllBytes("C:\Install\be2.jpg")) -Confirm:$false

Assistance on how to make it work with the EXO V2 module would be most welcome. Thanks.

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,177 questions
{count} votes

14 answers

Sort by: Most helpful
  1. Hans Hedman 56 Reputation points
    2021-04-06T13:55:07.013+00:00

    I got a message yesterday that it should be working now and indeed after updating EXO V2 from 2.0.3 to 2.0.4 with the command Update-Module -Name ExchangeOnlineManagement in an elevated PS prompt it is now working!
    It is still painfully slow to upload pictures but it works :-)

    0 comments No comments

  2. Anonymous
    2021-04-06T14:02:42.457+00:00

    Agreed. I had only a little time, but I also verified that Set-UserPhoto did indeed work on one account without issue. Beginning the modification of our codebase today...

    0 comments No comments

  3. Navin Gupta 11 Reputation points
    2021-04-06T14:33:21.633+00:00

    Folks

    Set-UserPhoto is now supported with CBA flow in EXO V2 module. Please do test and share your feedback here. There shouldn't be any impact on speed of running the cmdlets when CBA is used. However, we look forward to hearing from you all if the performance issue is consistent.

    Please update your module to the most recent version 2.0.4

    Regards
    Exchange Online Admin Team


  4. Jeffry A. Spain 1 Reputation point
    2021-04-06T15:20:33.987+00:00

    @Navin Gupta Confirming that Set-UserPhoto is working with ExchangeOnlineManagement v2.0.4 and certificate-based authentication. Thanks for fixing this. Jeff.

    0 comments No comments