How to fix weird registry error when using PowerShell Graph SDK to update a user's profile photo

Gill, Tim 25 Reputation points
2024-02-26T23:59:44.1233333+00:00

[UPDATE] As of 4/25/2024 (tested), the latest version of the Graph SDK (2.18.0) has resolved these issues. Per GitHub, the fixes were rolled out with 2.17.0, so that version and any further versions should work just fine. PREVIOUS WORKAROUND was to downgrade to 2.10.0.

------ ORIGINAL POST BELOW ------

I have connected successfully to Graph using PowerShell Graph SDK. I have tested this using two different connection methods (DelegatedUser with Token, and App Secret). I can perform various operations just fine using the Graph PowerShell SDK, but this one command to update a user's profile photo (Set-MgUserPhotoContent) always returns the same error (see bottom of post).

I have confirmed the following commands are working just fine:

  • Create a folder in another user's mailbox using New-MgUserMailFolder
  • Get another user's profile photo using Get-MgUserPhotoContent

Problems seen so far in Graph module v2.15.0):

  1. Error when running Set-MgUserPhotoContent (see below) - Registry error
  2. Error when running Remove-MgUserPhoto - Cmdlet unavailable

So it's not my connection to Graph, and I don't believe it's my permissions. Here is an output from Get-MGContext, showing the User.ReadWrite.All permission:User's image

$UpdatePhotoResult = Set-MgUserPhotoContent -UserId $EmailAddress -InFile $InFilePath

The error below has occurred on my own Win11 workstation and on a Server 2016 server.

Set-MgUserPhotoContent : Could not load file or assembly 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.
At line:1 char:5

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,646 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Gill, Tim 25 Reputation points
    2024-03-14T21:42:09.1266667+00:00

    [UPDATE] As of 4/25/2024 (tested), the latest version of the Graph SDK (2.18.0) has resolved these issues. Per GitHub, the fixes were rolled out with 2.17.0, so that version and any further versions should work just fine.

    Here are the commands to use to revert to a previous version (in this case, 2.10.0):

    ###Uninstall Microsoft Graph SDK (including all sub-modules) 
    Uninstall-Module Microsoft.Graph -AllVersions 
    Get-InstalledModule Microsoft.Graph.* | %{ if($_.Name -ne "Microsoft.Graph.Authentication"){ Uninstall-Module $_.Name -AllowPrerelease -AllVersions } } 
    Uninstall-Module Microsoft.Graph.Authentication -AllowPrerelease -AllVersions
    
    ###Install the Microsoft Graph SDK (specific older version)
    Install-Module Microsoft.Graph -RequiredVersion "2.10.0" -Force
    
    2 people found this answer helpful.

  2. Haus, Rene 0 Reputation points
    2024-03-27T07:26:00.19+00:00

    Sadly those commands will be nececarcy to change user Photos in the near future - i hope Microsoft fixes this fast :

    https://techcommunity.microsoft.com/t5/exchange-team-blog/deprecation-of-exchange-online-powershell-userphoto-cmdlets/bc-p/4098052#M38425


  3. Gill, Tim 25 Reputation points
    2024-04-26T16:45:01.7466667+00:00

    As of 4/25/2024 (tested), the latest version of the Graph SDK (2.18.0) has resolved these issues. Per GitHub, the fixes were rolled out with 2.17.0, so that version and any further versions should work just fine.

    0 comments No comments