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. Navin Gupta 11 Reputation points
    2020-09-23T10:28:02.7+00:00

    Hi

    Set-UserPhoto cmdlet uses a unique authentication method internally during server to server calls. This method is currently not supported in Certificate Based Authentication flows. Only Set-UserPhoto is one such cmdlet not supported in CBA ( https://aka.ms/exov2-cba )

    Can we update the title to "Set-UserPhoto doesn't work with CBA flow in EXO V2 module".

    We believe Setting user photo may not be a high frequency automation scenario. Can you explain more about the use-case and why you need to do it un-attended scripting on a regular basis ?
    That will help us prioritize.

    Regards
    Navin
    Exchange Online Team


  2. Nate Pope 1 Reputation point
    2020-10-23T20:56:05.903+00:00

    I wish I would have found this much earlier... Spent too much time trying to automate this exact problem of HR updating photos and needing the new photos to be uploaded to Azure.
    How do we get set-userphoto to support CBA? @Navin Gupta


  3. Mello, John 1 Reputation point
    2021-01-27T22:27:51.64+00:00

    My company also relies on a daily automation to keep user photos in sync with our HR system. As we are migrating all our Exchange related PowerShell scripts to the new module and certificate based automation it was disappointing to discover that these cmdlets were not available.

    0 comments No comments

  4. Escamilla, Jeffe 1 Reputation point
    2021-01-29T16:23:04.91+00:00

    Add me to this list too. We are trying to updated our automated process which can process up to 10-15 pictures per day and now they're all broken. Microsoft, this is definitely a "high frequency automation scenario" and needs to be addressed.

    0 comments No comments

  5. Anonymous
    2021-01-29T17:49:03.35+00:00

    Ours is an organization of about 30K users - we averaged about 23 a day over the last week. Our cloud-only account workaround is a life-saver.

    0 comments No comments